sc/source/core/data/documen3.cxx |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 82594fd81ba375d5e7ed919bef0b7b4b8072c02f
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Thu Oct 20 09:22:22 2022 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Thu Oct 20 11:32:12 2022 +0200

    Use stable_sort for collator-backed sorting
    
    ...where ScTypeStrData::LessCase(In)sensitive is implemented in terms of
    ScGlobal::Get(Case)Collator().compareString.  And that apparently implements
    only a strict weak ordering (in the C++ Standard's meaning of the term) 
rather
    than a strict total ordering (i.e., sorts different strings into equivalence
    classes, e.g., ScGlobal::GetCollator().compareString("guet", "guͤt") 
returns 0).
    
    With a randomizing debug-mode libc++, tests recently added to 
UITest_autofilter
    failed for me with
    
    > FAIL: test_tdf123095 (autofilterBugs.autofilter)
    > ----------------------------------------------------------------------
    > Traceback (most recent call last):
    >   File "sc/qa/uitest/autofilter/autofilterBugs.py", line 45, in 
test_tdf123095
    >     self.assertEqual(get_state_as_dict(xTreeList.getChild("0"))["Text"], 
"乙二醇(进口料件)")
    > AssertionError: '乙二醇(进口料件)' != '乙二醇(进口料件)'
    > - 乙二醇(进口料件)
    > ?    ^    ^
    > + 乙二醇(进口料件)
    > ?    ^    ^
    
    when _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED is e.g. 
140434132192856
    and
    
    > FAIL: test_tdf125363 (autofilterBugs.autofilter)
    > ----------------------------------------------------------------------
    > Traceback (most recent call last):
    >   File "sc/qa/uitest/autofilter/autofilterBugs.py", line 69, in 
test_tdf125363
    >     self.assertEqual(get_state_as_dict(xTreeList.getChild("0"))["Text"], 
"guet")
    > AssertionError: 'guͤt' != 'guet'
    > - guͤt
    > ?   ^
    > + guet
    > ?   ^
    
    when _LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY_SEED is e.g. 
139927542230616.
    
    (Those tests only required the !bCaseSens case to be stable_sort'ed, but it
    looks plausible that the bCaseSens case would suffer from the same issue, so
    lets stable_sort that one too.)
    
    Change-Id: I860ae7b58f09c85da82fca99a2962f12d70d2202
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141548
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index c1bdd76c6780..2f802a810ba1 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -83,7 +83,7 @@ void sortAndRemoveDuplicates(std::vector<ScTypedStrData>& 
rStrings, bool bCaseSe
 {
     if (bCaseSens)
     {
-        std::sort(rStrings.begin(), rStrings.end(), 
ScTypedStrData::LessCaseSensitive());
+        std::stable_sort(rStrings.begin(), rStrings.end(), 
ScTypedStrData::LessCaseSensitive());
         std::vector<ScTypedStrData>::iterator it =
             std::unique(rStrings.begin(), rStrings.end(), 
ScTypedStrData::EqualCaseSensitive());
         rStrings.erase(it, rStrings.end());
@@ -94,7 +94,7 @@ void sortAndRemoveDuplicates(std::vector<ScTypedStrData>& 
rStrings, bool bCaseSe
     }
     else
     {
-        std::sort(rStrings.begin(), rStrings.end(), 
ScTypedStrData::LessCaseInsensitive());
+        std::stable_sort(rStrings.begin(), rStrings.end(), 
ScTypedStrData::LessCaseInsensitive());
         std::vector<ScTypedStrData>::iterator it =
             std::unique(rStrings.begin(), rStrings.end(), 
ScTypedStrData::EqualCaseInsensitive());
         rStrings.erase(it, rStrings.end());

Reply via email to