From d6fb5ca5661195520ca7a7ca2d0145a1e11be099 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 14 Oct 2017 12:42:16 +0200 Subject: dyncolcontainer: use ScCompressedArray for pColWidth and enhance ScCompressedArray with an iterator to avoid O(n^2) "for" loops. Change-Id: I7d8fda8306b0a5c73bf373b3991e1c07271bc9d9 Reviewed-on: https://gerrit.libreoffice.org/43387 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/inc/compressedarray.hxx | 29 +++++++++++++++++++++++++++-- sc/inc/table.hxx | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'sc/inc') diff --git a/sc/inc/compressedarray.hxx b/sc/inc/compressedarray.hxx index e95c036991e7..86063049b774 100644 --- a/sc/inc/compressedarray.hxx +++ b/sc/inc/compressedarray.hxx @@ -29,7 +29,7 @@ const size_t nScCompressedArrayDelta = 4; /** Compressed array of row (or column) entries, e.g. heights, flags, ... - The array stores ranges of values such that consecutive values occupy only + The array stores ranges of values such that equal consecutive values occupy only one entry. Initially it consists of one DataEntry with an implied start row/column of 0 and an end row/column of access type maximum value. @@ -48,6 +48,19 @@ const size_t nScCompressedArrayDelta = 4; template< typename A, typename D > class ScCompressedArray { public: + class Iterator + { + friend ScCompressedArray; + const ScCompressedArray& mrArray; + size_t mnIndex = 0; + A mnRegion = 0; + Iterator(const ScCompressedArray& rArray) : mrArray(rArray) {} + Iterator(const ScCompressedArray& rArray, size_t nIndex, A nRegion) : mrArray(rArray), mnIndex(nIndex), mnRegion(nRegion) {} + public: + void operator++(); + Iterator operator+(size_t) const; + const D & operator*() const { return mrArray.pData[mnIndex].aValue; } + }; struct DataEntry { A nEnd; // start is end of previous entry + 1 @@ -67,30 +80,42 @@ public: void Reset( const D& rValue ); void SetValue( A nPos, const D& rValue ); void SetValue( A nStart, A nEnd, const D& rValue ); + SAL_WARN_UNUSED_RESULT const D& GetValue( A nPos ) const; + SAL_WARN_UNUSED_RESULT + A GetLastPos() const { return pData[nCount-1].nEnd; } /** Get value for a row, and it's region end row */ + SAL_WARN_UNUSED_RESULT const D& GetValue( A nPos, size_t& nIndex, A& nEnd ) const; /** Get next value and it's region end row. If nIndex=nCount, the value of the last entry is returned again. */ + SAL_WARN_UNUSED_RESULT const D& GetNextValue( size_t& nIndex, A& nEnd ) const; /** Insert rows before nStart and copy value for inserted rows from nStart-1, return that value. */ const D& Insert( A nStart, size_t nCount ); + void InsertPreservingSize( A nStart, size_t nCount, const D& rFillValue ); void Remove( A nStart, size_t nCount ); + void RemovePreservingSize( A nStart, size_t nCount, const D& rFillValue ); /** Copy rArray.nStart+nSourceDy to this.nStart */ void CopyFrom( const ScCompressedArray& rArray, - A nStart, A nEnd ); + A nStart, A nEnd ) + { CopyFrom(rArray, nStart, nEnd, nStart); } + void CopyFrom( const ScCompressedArray& rArray, + A nDestStart, A nDestEnd, A nSrcStart ); // methods public for the coupled array sum methods /** Obtain index into entries for nPos */ SC_DLLPUBLIC size_t Search( A nPos ) const; + Iterator begin() const { return Iterator(*this); } + protected: size_t nCount; size_t nLimit; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 10974065d571..adf2a8743c2e 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -177,7 +177,7 @@ private: std::unique_ptr pTabProtection; - std::unique_ptr pColWidth; + std::unique_ptr> mpColWidth; std::unique_ptr mpRowHeights; std::unique_ptr pColFlags; -- cgit