diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-04-07 16:25:49 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-04-08 08:52:09 +0200 |
commit | 7be675cdfad328667bfbab043d71539dfd9e6fe6 (patch) | |
tree | 94a83c67d26aaffb513863a6ab0e4f8f72b2dc4d /vcl | |
parent | 1d556ff84dce01531ee334dc1408cebe50e97d22 (diff) |
improve combining in hash functions
specifically, use boost::hash_combine to combine values in hash
functions, except for a couple of places where I use the
small-prime-number strategy popular in the Java world, to avoid
including boost in header files that are widely shared.
Change-Id: I0e184c9ec8803bf09fc6e84fe20131b203e1652a
Reviewed-on: https://gerrit.libreoffice.org/70384
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/font/fontinstance.cxx | 7 | ||||
-rw-r--r-- | vcl/unx/generic/glyphs/glyphcache.cxx | 18 | ||||
-rw-r--r-- | vcl/unx/generic/printer/ppdparser.cxx | 12 |
3 files changed, 20 insertions, 17 deletions
diff --git a/vcl/source/font/fontinstance.cxx b/vcl/source/font/fontinstance.cxx index 595259731db1..bcbbe6d94d9d 100644 --- a/vcl/source/font/fontinstance.cxx +++ b/vcl/source/font/fontinstance.cxx @@ -32,9 +32,10 @@ namespace std { size_t operator()(const pair< sal_UCS4, FontWeight >& rData) const { - size_t h1 = hash<sal_UCS4>()(rData.first); - size_t h2 = hash<int>()(rData.second); - return h1 ^ h2; + std::size_t seed = 0; + boost::hash_combine(seed, rData.first); + boost::hash_combine(seed, rData.second); + return seed; } }; } diff --git a/vcl/unx/generic/glyphs/glyphcache.cxx b/vcl/unx/generic/glyphs/glyphcache.cxx index 0aa8be45e84a..558e3d8c3323 100644 --- a/vcl/unx/generic/glyphs/glyphcache.cxx +++ b/vcl/unx/generic/glyphs/glyphcache.cxx @@ -85,15 +85,15 @@ size_t GlyphCache::IFSD_Hash::operator()(const rtl::Reference<LogicalFontInstanc nFontId ^= aFeatName.hashCode(); } - size_t nHash = nFontId << 8; - nHash += rFontSelData.mnHeight; - nHash += rFontSelData.mnOrientation; - nHash += size_t(rFontSelData.mbVertical); - nHash += rFontSelData.GetItalic(); - nHash += rFontSelData.GetWeight(); - nHash += static_cast<sal_uInt16>(rFontSelData.meLanguage); - - return nHash; + std::size_t seed = 0; + boost::hash_combine(seed, nFontId); + boost::hash_combine(seed, rFontSelData.mnHeight); + boost::hash_combine(seed, rFontSelData.mnOrientation); + boost::hash_combine(seed, size_t(rFontSelData.mbVertical)); + boost::hash_combine(seed, rFontSelData.GetItalic()); + boost::hash_combine(seed, rFontSelData.GetWeight()); + boost::hash_combine(seed, static_cast<sal_uInt16>(rFontSelData.meLanguage)); + return seed; } bool GlyphCache::IFSD_Equal::operator()(const rtl::Reference<LogicalFontInstance>& rAFontInstance, diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx index 923d8612e7a1..aa99e3638580 100644 --- a/vcl/unx/generic/printer/ppdparser.cxx +++ b/vcl/unx/generic/printer/ppdparser.cxx @@ -54,6 +54,7 @@ #include <config_dbus.h> #include <config_gio.h> +#include <boost/functional/hash.hpp> namespace psp { @@ -73,11 +74,12 @@ namespace psp struct LocaleHash { size_t operator()(const css::lang::Locale& rLocale) const - { return - static_cast<size_t>(rLocale.Language.hashCode()) - ^ static_cast<size_t>(rLocale.Country.hashCode()) - ^ static_cast<size_t>(rLocale.Variant.hashCode()) - ; + { + std::size_t seed = 0; + boost::hash_combine(seed, rLocale.Language.hashCode()); + boost::hash_combine(seed, rLocale.Country.hashCode()); + boost::hash_combine(seed, rLocale.Variant.hashCode()); + return seed; } }; |