sw/source/core/unocore/unoportenum.cxx |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

New commits:
commit a0dd4cd98504124362524727c5f9eae731c1944f
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed May 3 15:07:15 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed May 3 18:33:58 2023 +0200

    tdf#136991 reorganise lcl_ExportHints loop
    
    to reduce some CPU cycles by avoid calling GetSortedByEnd multiple times
    for the same key.
    
    Change-Id: I2c77c1f70f3c7d3e2f5801edfacc2e511d7b375f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151324
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/unocore/unoportenum.cxx 
b/sw/source/core/unocore/unoportenum.cxx
index b434ec772381..db567f3cbf05 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -717,15 +717,19 @@ lcl_ExportHints(
     SwDoc& rDoc = pUnoCursor->GetDoc();
     //search for special text attributes - first some ends
     size_t nEndIndex = 0;
-    sal_Int32 nNextEnd = 0;
     const auto nHintsCount = pHints->Count();
-    while(nEndIndex < nHintsCount &&
-        (!pHints->GetSortedByEnd(nEndIndex)->GetEnd() ||
-        nCurrentIndex >= (nNextEnd = 
(*pHints->GetSortedByEnd(nEndIndex)->GetEnd()))))
+    for (;;)
     {
-        if(pHints->GetSortedByEnd(nEndIndex)->GetEnd())
+        if (nEndIndex >= nHintsCount)
+            break;
+        SwTextAttr * const pAttr = pHints->GetSortedByEnd(nEndIndex);
+        const sal_Int32* pAttrEnd = pAttr->GetEnd();
+        sal_Int32 nNextEnd = 0;
+        if (pAttrEnd &&
+            nCurrentIndex < (nNextEnd = (*pAttrEnd)))
+            break;
+        if(pAttrEnd)
         {
-            SwTextAttr * const pAttr = pHints->GetSortedByEnd(nEndIndex);
             if (nNextEnd == nCurrentIndex)
             {
                 const sal_uInt16 nWhich( pAttr->Which() );
@@ -1037,7 +1041,7 @@ lcl_ExportHints(
             nStartIndex++;
 
         nEndIndex = 0;
-        nNextEnd = 0;
+        sal_Int32 nNextEnd = 0;
         while(nEndIndex < pHints->Count() &&
             nCurrentIndex >= (nNextEnd = 
pHints->GetSortedByEnd(nEndIndex)->GetAnyEnd()))
             nEndIndex++;

Reply via email to