diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-12-08 21:39:35 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-12-09 05:52:46 +0100 |
commit | 3cd30978ebfbde5425038281252e9b85ef3a3c48 (patch) | |
tree | 78841fd26fc42b465525a3d113d342bb544b7eb3 /basic | |
parent | 5f40fa6f29a2a51a5f843f7a92d57721e1b8d540 (diff) |
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@collabora.com>
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/runtime/runtime.cxx | 12 |
1 files changed, 12 insertions, 0 deletions
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); |