svx/source/svdraw/svdobj.cxx |   26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

New commits:
commit a05b8078278212af227dd0c0046d4ad9f231eb04
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Feb 10 13:27:36 2026 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Feb 13 09:38:33 2026 +0100

    tdf#170595 speed up SdrObject::MakeNameUnique a little
    
    we only need to check for strings with a similar baseline,
    which reduces time spent inserting into the hashset and
    probing the hashset
    
    Change-Id: I09e74fb4818f7decaf72c5cdc825de4b4b4fa0d8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199267
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index c71961a7f88f..b2982c7e8afd 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -3173,6 +3173,16 @@ void 
SdrObject::MakeNameUnique(std::unordered_set<OUString>& rNameSet)
     if (GetName().isEmpty())
         return;
 
+    OUString sName(GetName().trim());
+    OUString sRootName(sName);
+
+    if (!sName.isEmpty() && rtl::isAsciiDigit(sName[sName.getLength() - 1]))
+    {
+        sal_Int32 nPos(sName.getLength() - 1);
+        while (nPos > 0 && rtl::isAsciiDigit(sName[--nPos]));
+        sRootName = o3tl::trim(sName.subView(0, nPos + 1));
+    }
+
     if (rNameSet.empty())
     {
         SdrPage* pPage;
@@ -3185,21 +3195,15 @@ void 
SdrObject::MakeNameUnique(std::unordered_set<OUString>& rNameSet)
             {
                 pObj = aIter.Next();
                 if (pObj != this)
-                    rNameSet.insert(pObj->GetName());
+                {
+                    auto rName = pObj->GetName();
+                    if (rName.startsWith(sRootName))
+                        rNameSet.insert(rName);
+                }
             }
         }
     }
 
-    OUString sName(GetName().trim());
-    OUString sRootName(sName);
-
-    if (!sName.isEmpty() && rtl::isAsciiDigit(sName[sName.getLength() - 1]))
-    {
-        sal_Int32 nPos(sName.getLength() - 1);
-        while (nPos > 0 && rtl::isAsciiDigit(sName[--nPos]));
-        sRootName = o3tl::trim(sName.subView(0, nPos + 1));
-    }
-
     for (sal_uInt32 n = 1; rNameSet.find(sName) != rNameSet.end(); n++)
         sName = sRootName + " " + OUString::number(n);
     rNameSet.insert(sName);

Reply via email to