sw/source/core/bastyp/index.cxx |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

New commits:
commit 1920eb7843753392bd7581f02ff797f2f903c50a
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Mon Aug 15 19:04:54 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Aug 16 09:11:16 2022 +0200

    improve SwContentIndexReg::Update...UpdateMode::Negative
    
    the indexes in the linked list are stored in-order.
    So
    (a) there is no need to overwrite a value with the same value
    and
    (b) there is no need to walk the list backwards before going
    forwards
    
    Change-Id: I77d6b227c5c2eb8e70ce3975963ec2d1826d0246
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138321
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/bastyp/index.cxx b/sw/source/core/bastyp/index.cxx
index 15507ab083d3..f7868e8901e0 100644
--- a/sw/source/core/bastyp/index.cxx
+++ b/sw/source/core/bastyp/index.cxx
@@ -243,15 +243,12 @@ void SwContentIndexReg::Update(
     const sal_Int32 nNewVal = rIdx.m_nIndex;
     if (eMode & UpdateMode::Negative)
     {
-        const sal_Int32 nLast = rIdx.GetIndex() + nDiff;
-        while (pStt && pStt->m_nIndex == nNewVal)
-        {
-            pStt->m_nIndex = nNewVal;
-            pStt = pStt->m_pPrev;
-        }
+        const sal_Int32 nLast = rIdx.m_nIndex + nDiff;
         pStt = rIdx.m_pNext;
-        while (pStt && pStt->m_nIndex >= nNewVal
-                    && pStt->m_nIndex <= nLast)
+        // skip over the ones that already have the right value
+        while (pStt && pStt->m_nIndex == nNewVal)
+            pStt = pStt->m_pNext;
+        while (pStt && pStt->m_nIndex <= nLast)
         {
             pStt->m_nIndex = nNewVal;
             pStt = pStt->m_pNext;

Reply via email to