svx/source/tbxctrls/tbcontrl.cxx |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

New commits:
commit 2be27b33cc2965bf1b6f550768b23e1dd27a597a
Author:     Noel Grandin <[email protected]>
AuthorDate: Mon Jan 5 10:29:08 2026 +0200
Commit:     Michael Stahl <[email protected]>
CommitDate: Tue Feb 24 13:56:41 2026 +0100

    tdf#166684 fix O(n^2) loop in SvxStyleToolBoxControl::FillStyleBox
    
    after
        commit f4c7443b561eaa58be3eea5bd2598a7090ef386b
        Author: Szymon Kłos <[email protected]>
        Date:   Fri Dec 26 08:31:12 2025 +0000
        tdf#108239 sidebar: unify style list with notebookbar
    
    Change-Id: I5b7d2666af9f272f932e0b3c0b22ad626cf9001a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196535
    Reviewed-by: Tomaž Vajngerl <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    (cherry picked from commit 47f332bf69d495563c720949980c72c96dec41e6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196534
    Reviewed-by: Noel Grandin <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 1d9cc5964c7a2fd4dd9326c2c0bfa6ee48d67006)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200080
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 019ff54a38e8..beda9d000c76 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -176,11 +176,6 @@ public:
             m_xWidget->set_entry_text(rText);
     }
 
-    int find_text(const OUString& rText)
-    {
-        return m_xWidget->find_text(rText);
-    }
-
     void set_active(int nActive)
     {
         m_xWidget->set_active(nActive);
@@ -3271,6 +3266,8 @@ void SvxStyleToolBoxControl::FillStyleBox()
     pBox->clear();
 
     std::vector<OUString> aStyles;
+    // use a set to avoid O(n^2) performance problem in insert loop
+    std::unordered_set<OUString> aStylesSet;
 
     // add used styles
     pStyle = xIter->Next();
@@ -3291,13 +3288,17 @@ void SvxStyleToolBoxControl::FillStyleBox()
             if ( aStyles.size() + pBox->get_count() > 12)
                 break;
             pBox->append_text(rStyle.second);
+            aStylesSet.insert(rStyle.second);
         }
     }
     std::sort(aStyles.begin(), aStyles.end());
 
     for (const auto& rStyle : aStyles)
-        if (pBox->find_text(rStyle) == -1)
+    {
+        // do not duplicate default styles
+        if (aStylesSet.insert(rStyle).second)
             pBox->append_text(rStyle);
+    }
 
     if ((m_pImpl->bSpecModeWriter || m_pImpl->bSpecModeCalc) && 
!comphelper::LibreOfficeKit::isActive())
         pBox->append_text(m_pImpl->aMore);

Reply via email to