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 /xmloff | |
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 'xmloff')
-rw-r--r-- | xmloff/inc/StyleMap.hxx | 7 | ||||
-rw-r--r-- | xmloff/source/core/xmltkmap.cxx | 6 | ||||
-rw-r--r-- | xmloff/source/forms/property_meta_data.cxx | 6 | ||||
-rw-r--r-- | xmloff/source/transform/TransformerActions.hxx | 7 |
4 files changed, 20 insertions, 6 deletions
diff --git a/xmloff/inc/StyleMap.hxx b/xmloff/inc/StyleMap.hxx index 8fb76e61104d..aef67399b8cd 100644 --- a/xmloff/inc/StyleMap.hxx +++ b/xmloff/inc/StyleMap.hxx @@ -22,6 +22,7 @@ #include <com/sun/star/lang/XUnoTunnel.hpp> #include <cppuhelper/implbase.hxx> +#include <boost/functional/hash.hpp> #include <unordered_map> struct StyleNameKey_Impl @@ -46,8 +47,10 @@ struct StyleNameHash_Impl inline size_t StyleNameHash_Impl::operator()( const StyleNameKey_Impl& r ) const { - return static_cast< size_t >( r.m_nFamily ) + - static_cast< size_t >( r.m_aName.hashCode() ); + std::size_t seed = 0; + boost::hash_combine(seed, r.m_nFamily); + boost::hash_combine(seed, r.m_aName.hashCode()); + return seed; } inline bool StyleNameHash_Impl::operator()( diff --git a/xmloff/source/core/xmltkmap.cxx b/xmloff/source/core/xmltkmap.cxx index 1aca38975d9b..d89eb9621638 100644 --- a/xmloff/source/core/xmltkmap.cxx +++ b/xmloff/source/core/xmltkmap.cxx @@ -20,6 +20,7 @@ #include <rtl/ustring.hxx> #include <xmloff/xmltkmap.hxx> #include <xmloff/xmltoken.hxx> +#include <boost/functional/hash.hpp> #include <unordered_map> #include <utility> @@ -33,7 +34,10 @@ private: { std::size_t operator()(const std::pair<sal_uInt16,OUString> &pair) const { - return static_cast<std::size_t>( pair.first | pair.second.hashCode() ); + std::size_t seed = 0; + boost::hash_combine(seed, pair.first); + boost::hash_combine(seed, pair.second.hashCode()); + return seed; } }; std::unordered_map< std::pair<sal_uInt16, OUString>, diff --git a/xmloff/source/forms/property_meta_data.cxx b/xmloff/source/forms/property_meta_data.cxx index 87ccd36fc160..edf505faa45d 100644 --- a/xmloff/source/forms/property_meta_data.cxx +++ b/xmloff/source/forms/property_meta_data.cxx @@ -24,6 +24,7 @@ #include <xmloff/xmltoken.hxx> #include <xmloff/xmlnmspe.hxx> +#include <boost/functional/hash.hpp> #include <tools/debug.hxx> #include <osl/diagnose.h> #include <sal/log.hxx> @@ -128,7 +129,10 @@ namespace xmloff { namespace metadata { size_t operator()( const AttributeDescription& i_attribute ) const { - return size_t( i_attribute.attributeToken * 100 ) + size_t( i_attribute.namespacePrefix ); + std::size_t seed = 0; + boost::hash_combine(seed, i_attribute.attributeToken); + boost::hash_combine(seed, i_attribute.namespacePrefix); + return seed; } }; diff --git a/xmloff/source/transform/TransformerActions.hxx b/xmloff/source/transform/TransformerActions.hxx index 3c7f61c7c365..17109c031808 100644 --- a/xmloff/source/transform/TransformerActions.hxx +++ b/xmloff/source/transform/TransformerActions.hxx @@ -24,6 +24,7 @@ #include <xmloff/nmspmap.hxx> #include "TransformerActionInit.hxx" #include "TransformerAction.hxx" +#include <boost/functional/hash.hpp> #include <unordered_map> struct NameKey_Impl @@ -57,8 +58,10 @@ struct NameHash_Impl inline size_t NameHash_Impl::operator()( const NameKey_Impl& r ) const { - return static_cast< size_t >( r.m_nPrefix ) + - static_cast< size_t >( r.m_aLocalName.hashCode() ); + std::size_t seed = 0; + boost::hash_combine(seed, r.m_nPrefix); + boost::hash_combine(seed, r.m_aLocalName.hashCode()); + return seed; } inline bool NameHash_Impl::operator()( |