diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2022-08-20 10:57:19 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-22 09:35:31 +0200 |
commit | db04b3e154a1fb8f222232ef969bb3617e051329 (patch) | |
tree | 84195e6f47abd82024127ced37405585df7708bb /include/rtl/ustring.hxx | |
parent | b2b3b4e833484aa70cb73b296bb62cdb0304eac9 (diff) |
return 64-bit hash for O[U]String
which gives better performance when putting strings into hashed
containers that expect good key distribution.
This hash implementation is the same one that Java uses.
Change-Id: Iae5cf3cd27309856acfa51781295f2e56c8e77db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138574
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/rtl/ustring.hxx')
-rw-r--r-- | include/rtl/ustring.hxx | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index e6d3ed682932..79ad75d8304d 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -3547,7 +3547,18 @@ template<> struct hash<::rtl::OUString> { std::size_t operator()(::rtl::OUString const & s) const - { return std::size_t(s.hashCode()); } + { + 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; + for (sal_Int32 i = 0, len = s.getLength(); i < len; ++i) + n = 31 * n + s[i]; + return n; + } + else + return std::size_t(s.hashCode()); + } }; } |