sc/inc/attarray.hxx | 2 +- sc/source/core/data/attarray.cxx | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-)
New commits: commit 6c247c2c867281181d3d35157bca5e72a3c0bca8 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Oct 10 12:55:20 2023 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Oct 11 07:28:20 2023 +0200 cool#7330 calc perf: PaintTile's FillInfo try to spend a little less time here, when searching twice, we can use the index result of the first search as a hint Change-Id: I7fc0c2fb4e5e338d2c3f8a3d642043a1b301e7b9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157749 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/inc/attarray.hxx b/sc/inc/attarray.hxx index cbc8f7cfe2f9..521f3b7bb1d6 100644 --- a/sc/inc/attarray.hxx +++ b/sc/inc/attarray.hxx @@ -183,7 +183,7 @@ public: bool ApplyFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags ); bool RemoveFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags ); - bool Search( SCROW nRow, SCSIZE& nIndex ) const; + bool Search( SCROW nRow, SCSIZE& nIndex, std::optional<SCROW> nIndexHint = {} ) const; bool HasAttrib( SCROW nRow1, SCROW nRow2, HasAttrFlags nMask ) const; bool HasAttrib( SCROW nRow, HasAttrFlags nMask, SCROW* nStartRow = nullptr, SCROW* nEndRow = nullptr ) const; diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx index 2efd31c7675f..b6d062b93d66 100644 --- a/sc/source/core/data/attarray.cxx +++ b/sc/source/core/data/attarray.cxx @@ -190,9 +190,11 @@ bool ScAttrArray::Concat(SCSIZE nPos) * * Iterative implementation of Binary Search * The same implementation was used inside ScMarkArray::Search(). + * + * @param oIndexHint, hint for the start of the search, useful when searching twice for successive values */ -bool ScAttrArray::Search( SCROW nRow, SCSIZE& nIndex ) const +bool ScAttrArray::Search( SCROW nRow, SCSIZE& nIndex, std::optional<SCROW> oIndexHint ) const { /* auto it = std::lower_bound(mvData.begin(), mvData.end(), nRow, [] (const ScAttrEntry &r1, SCROW nRow) @@ -209,7 +211,8 @@ bool ScAttrArray::Search( SCROW nRow, SCSIZE& nIndex ) const tools::Long nHi = static_cast<tools::Long>(mvData.size()) - 1; tools::Long i = 0; - tools::Long nLo = 0; + assert((!oIndexHint || *oIndexHint <= nHi) && "bad index hint"); + tools::Long nLo = oIndexHint ? *oIndexHint : 0; while ( nLo <= nHi ) { @@ -1405,7 +1408,7 @@ bool ScAttrArray::HasAttrib( SCROW nRow1, SCROW nRow2, HasAttrFlags nMask ) cons SCSIZE nEndIndex; Search( nRow1, nStartIndex ); if (nRow1 != nRow2) - Search( nRow2, nEndIndex ); + Search( nRow2, nEndIndex, /*hint*/nStartIndex ); else nEndIndex = nStartIndex; bool bFound = false;