[Libreoffice-bugs] [Bug 126663] XLSX: LibreOffice is freezed when I try open Style list in Sidebar

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Sun Aug 4 18:12:08 UTC 2019


https://bugs.documentfoundation.org/show_bug.cgi?id=126663

--- Comment #5 from Julien Nabet <serval2412 at yahoo.fr> ---
This part seems fishy:
https://opengrok.libreoffice.org/xref/core/sfx2/source/dialog/templdlg.cxx?r=45839115#1185
1185      while( pStyle )
1186      {
1187          //Bubblesort
1188          size_t nPos;
1189          for(nPos = aStrings.size(); nPos &&
aSorter.compare(aStrings[nPos-1], pStyle->GetName()) > 0; --nPos)
1190          {};
1191          aStrings.insert(aStrings.begin() + nPos, pStyle->GetName());
1192          pStyle = pStyleSheetPool->Next();
1193      }

Wouldn't it be better to push_back every pStyle names in aStrings with the
loop, then sort once afterwards with std::sort ?

Eg:
diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx
index 8cc0240f5f6f..c9e654afed45 100644
--- a/sfx2/source/dialog/templdlg.cxx
+++ b/sfx2/source/dialog/templdlg.cxx
@@ -1184,13 +1184,13 @@ void
SfxCommonTemplateDialog_Impl::UpdateStyles_Impl(StyleFlags nFlags)

     while( pStyle )
     {
-        //Bubblesort
-        size_t nPos;
-        for(nPos = aStrings.size(); nPos && aSorter.compare(aStrings[nPos-1],
pStyle->GetName()) > 0; --nPos)
-        {};
-        aStrings.insert(aStrings.begin() + nPos, pStyle->GetName());
+        aStrings.push_back(pStyle->GetName());
         pStyle = pStyleSheetPool->Next();
     }
+    std::sort(aStrings.begin(), aStrings.end(),
+       [&aSorter](const OUString& rLHS, const OUString& rRHS) {
+       return aSorter.compare(rLHS, rRHS) < 0;
+       });

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20190804/07f30915/attachment.html>


More information about the Libreoffice-bugs mailing list