include/rtl/string.hxx  |    4 ++--
 include/rtl/ustring.hxx |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 02ffa01b5e2e7697d6b386419e88a9b8910ad31f
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sat Jan 6 15:43:19 2024 +0600
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Jan 9 15:10:01 2024 +0100

    tdf#159018: make 64-bit hash algorithm similar to 32-bit one
    
    The magic of choosing a substitution font depends on the order of
    fontfaces returned from PhysicalFontCollection::GetFontFaceCollection
    (called from WinGlyphFallbackSubstititution::FindFontSubstitute).
    Since commit db04b3e154a1fb8f222232ef969bb3617e051329 (return 64-bit
    hash for O[U]String, 2022-08-22), the order has changed, which
    resulted in different fallbacks in some documents (which aren't
    well-formed in respect to their formatting, so when they work,
    it's just luck).
    
    The difference was because the 64-bit hash implementation was
    modelled after Java one. This patch makes the code follow the
    algorithm in rtl::str::hashCode_WithLength, used in 32-bit hash,
    which restores the order (at least for my system). Not reliable,
    just "why not".
    
    Change-Id: I3c482e86bee79d6c9c6981300518c4ff6b7f29d5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161706
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 4eeb6178fb9fb499bc417a42f8d6d0bdde9acb8e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161763
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx
index 091f224b25d6..7e47b917100e 100644
--- a/include/rtl/string.hxx
+++ b/include/rtl/string.hxx
@@ -2391,9 +2391,9 @@ struct hash<::rtl::OString>
         if constexpr (sizeof(std::size_t) == 8)
         {
             // return a hash that uses the full 64-bit range instead of a 
32-bit value
-            size_t n = 0;
+            size_t n = s.getLength();
             for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
-                n = 31 * n + s[i];
+                n = 37 * n + s[i];
             return n;
         }
         else
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index c4869f43a8f0..b5e27a2eabb4 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -3593,9 +3593,9 @@ struct hash<::rtl::OUString>
         if constexpr (sizeof(std::size_t) == 8)
         {
             // return a hash that uses the full 64-bit range instead of a 
32-bit value
-            size_t n = 0;
+            size_t n = s.getLength();
             for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i)
-                n = 31 * n + s[i];
+                n = 37 * n + s[i];
             return n;
         }
         else

Reply via email to