[Libreoffice-commits] core.git: basic/source
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Mon Dec 9 04:53:36 UTC 2019
basic/source/runtime/runtime.cxx | 12 ++++++++++++
1 file changed, 12 insertions(+)
New commits:
commit 3cd30978ebfbde5425038281252e9b85ef3a3c48
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun Dec 8 21:39:35 2019 +0100
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Mon Dec 9 05:52:46 2019 +0100
Preallocate array when initializing/preserving
This avoids repeated std::vector::resize in SbxArray::GetRef32 called from
SbxArray::Put32 called in loops for each array element when max index is
known in advance.
Change-Id: Ib2d1fe27820b9ede1426e206794f8cc729998841
Reviewed-on: https://gerrit.libreoffice.org/84722
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 232778c73af3..257aca35dcae 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -2205,6 +2205,7 @@ static bool implRestorePreservedArray(SbxDimArray* pNewArray, SbxArrayRef& rrefR
std::unique_ptr<sal_Int32[]> pLowerBounds(new sal_Int32[nDimsNew]);
std::unique_ptr<sal_Int32[]> pUpperBounds(new sal_Int32[nDimsNew]);
std::unique_ptr<sal_Int32[]> pActualIndices(new sal_Int32[nDimsNew]);
+ bool bNeedsPreallocation = true;
// Compare bounds
for (short i = 1; i <= nDimsNew; i++)
@@ -2218,7 +2219,14 @@ static bool implRestorePreservedArray(SbxDimArray* pNewArray, SbxArrayRef& rrefR
short j = i - 1;
pActualIndices[j] = pLowerBounds[j] = lBoundNew;
pUpperBounds[j] = uBoundNew;
+ if (lBoundNew > uBoundNew) // No elements in the dimension -> no elements to restore
+ bNeedsPreallocation = false;
}
+
+ // Optimization: pre-allocate underlying container
+ if (bNeedsPreallocation)
+ pNewArray->Put32(nullptr, pUpperBounds.get());
+
// Copy data from old array by going recursively through all dimensions
// (It would be faster to work on the flat internal data array of an
// SbyArray but this solution is clearer and easier)
@@ -4314,6 +4322,10 @@ void SbiRuntime::StepDCREATE_IMPL( sal_uInt32 nOp1, sal_uInt32 nOp2 )
nTotalSize *= nSize;
}
+ // Optimization: pre-allocate underlying container
+ if (nTotalSize > 0)
+ pArray->SbxArray::GetRef32(nTotalSize - 1);
+
// First, fill those parts of the array that are preserved
bool bWasError = false;
const bool bRestored = implRestorePreservedArray(pArray, refRedimpArray, &bWasError);
More information about the Libreoffice-commits
mailing list