diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2017-10-14 12:42:16 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-17 08:55:14 +0200 |
commit | d6fb5ca5661195520ca7a7ca2d0145a1e11be099 (patch) | |
tree | d82ab460f7ed249b097033dbcd824d02430e5f04 /sc/inc | |
parent | 616f21db9e50a77b0c02dfb123f871a742f46216 (diff) |
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 <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/inc')
-rw-r--r-- | sc/inc/compressedarray.hxx | 29 | ||||
-rw-r--r-- | sc/inc/table.hxx | 2 |
2 files changed, 28 insertions, 3 deletions
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, nIndex is incremented first. If the resulting 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<ScTableProtection> pTabProtection; - std::unique_ptr<sal_uInt16[]> pColWidth; + std::unique_ptr<ScCompressedArray<SCCOL, sal_uInt16>> mpColWidth; std::unique_ptr<ScFlatUInt16RowSegments> mpRowHeights; std::unique_ptr<CRFlags[]> pColFlags; |