summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-10-10 12:55:20 +0200
committerCaolán McNamara <caolan.mcnamara@collabora.com>2023-10-12 10:19:40 +0200
commit9f03693227940abc761dc8d6964baf38c67e1090 (patch)
tree28c8a6308e5c4000b5248a426df1b66dc91e6173 /sc
parent2f60fa7ccdefd76b61e1c7b7cc27ae92824111da (diff)
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.grandin@collabora.co.uk> (cherry picked from commit 54d77f9a02530b8c5871e0aec9b3b4c94d82fbd3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157721 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/attarray.hxx2
-rw-r--r--sc/source/core/data/attarray.cxx9
2 files changed, 7 insertions, 4 deletions
diff --git a/sc/inc/attarray.hxx b/sc/inc/attarray.hxx
index 868118796560..672c29f41247 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 87fa2c11ccf1..406525e862c8 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -189,9 +189,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)
@@ -208,7 +210,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 )
{
@@ -1404,7 +1407,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;