summaryrefslogtreecommitdiff
path: root/sc/source/core/data/compressedarray.cxx
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2017-10-14 12:42:16 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-10-17 08:55:14 +0200
commitd6fb5ca5661195520ca7a7ca2d0145a1e11be099 (patch)
treed82ab460f7ed249b097033dbcd824d02430e5f04 /sc/source/core/data/compressedarray.cxx
parent616f21db9e50a77b0c02dfb123f871a742f46216 (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/source/core/data/compressedarray.cxx')
-rw-r--r--sc/source/core/data/compressedarray.cxx57
1 files changed, 50 insertions, 7 deletions
diff --git a/sc/source/core/data/compressedarray.cxx b/sc/source/core/data/compressedarray.cxx
index 5cbcb6073bd7..0b5308a4fe26 100644
--- a/sc/source/core/data/compressedarray.cxx
+++ b/sc/source/core/data/compressedarray.cxx
@@ -238,18 +238,18 @@ void ScCompressedArray<A,D>::SetValue( A nStart, A nEnd, const D& rValue )
}
template< typename A, typename D >
-void ScCompressedArray<A,D>::CopyFrom( const ScCompressedArray<A,D>& rArray, A nStart,
- A nEnd )
+void ScCompressedArray<A,D>::CopyFrom( const ScCompressedArray<A,D>& rArray, A nDestStart,
+ A nDestEnd, A nSrcStart )
{
size_t nIndex = 0;
A nRegionEnd;
- for (A j=nStart; j<=nEnd; ++j)
+ for (A j=nDestStart; j<=nDestEnd; ++j)
{
- const D& rValue = (j==nStart ?
- rArray.GetValue( j, nIndex, nRegionEnd) :
+ const D& rValue = (j==nDestStart ?
+ rArray.GetValue( j - nDestStart + nSrcStart, nIndex, nRegionEnd) :
rArray.GetNextValue( nIndex, nRegionEnd));
- if (nRegionEnd > nEnd)
- nRegionEnd = nEnd;
+ if (nRegionEnd > nDestEnd)
+ nRegionEnd = nDestEnd;
this->SetValue( j, nRegionEnd, rValue);
j = nRegionEnd;
}
@@ -278,6 +278,19 @@ const D& ScCompressedArray<A,D>::Insert( A nStart, size_t nAccessCount )
}
template< typename A, typename D >
+void ScCompressedArray<A,D>::InsertPreservingSize( A nStart, size_t nAccessCount, const D& rFillValue )
+{
+ const A nPrevLastPos = GetLastPos();
+
+ Insert(nStart, nAccessCount);
+ for (A i = nStart; i < A(nStart + nAccessCount); ++i)
+ SetValue(i, rFillValue);
+
+ const A nNewLastPos = GetLastPos();
+ Remove(nPrevLastPos, nNewLastPos - nPrevLastPos);
+}
+
+template< typename A, typename D >
void ScCompressedArray<A,D>::Remove( A nStart, size_t nAccessCount )
{
A nEnd = nStart + nAccessCount - 1;
@@ -313,6 +326,35 @@ void ScCompressedArray<A,D>::Remove( A nStart, size_t nAccessCount )
pData[nCount-1].nEnd = nMaxAccess;
}
+template< typename A, typename D >
+void ScCompressedArray<A,D>::RemovePreservingSize( A nStart, size_t nAccessCount, const D& rFillValue )
+{
+ const A nPrevLastPos = GetLastPos();
+
+ Remove(nStart, nAccessCount);
+
+ const A nNewLastPos = GetLastPos();
+ InsertPreservingSize(nNewLastPos, nNewLastPos - nPrevLastPos, rFillValue);
+}
+
+template< typename A, typename D >
+void ScCompressedArray<A,D>::Iterator::operator++()
+{
+ ++mnRegion;
+ if (mnRegion > mrArray.pData[mnIndex].nEnd)
+ ++mnIndex;
+}
+
+template< typename A, typename D >
+typename ScCompressedArray<A,D>::Iterator ScCompressedArray<A,D>::Iterator::operator+(size_t nAccessCount) const
+{
+ A nRegion = mnRegion + nAccessCount;
+ auto nIndex = mnIndex;
+ while (nRegion > mrArray.pData[nIndex].nEnd)
+ ++nIndex;
+ return Iterator(mrArray, nIndex, nRegion);
+}
+
// === ScBitMaskCompressedArray ==============================================
template< typename A, typename D >
@@ -417,5 +459,6 @@ A ScBitMaskCompressedArray<A,D>::GetLastAnyBitAccess( const D& rBitMask ) const
template class ScCompressedArray< SCROW, CRFlags>; // flags, base class
template class ScBitMaskCompressedArray< SCROW, CRFlags>; // flags
+template class ScCompressedArray< SCCOL, sal_uInt16>;
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */