summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-04-07 16:25:49 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-04-08 08:52:09 +0200
commit7be675cdfad328667bfbab043d71539dfd9e6fe6 (patch)
tree94a83c67d26aaffb513863a6ab0e4f8f72b2dc4d /sc
parent1d556ff84dce01531ee334dc1408cebe50e97d22 (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 'sc')
-rw-r--r--sc/inc/externalrefmgr.hxx9
-rw-r--r--sc/source/core/data/dpresfilter.cxx7
-rw-r--r--sc/source/ui/view/spellcheckcontext.cxx9
3 files changed, 18 insertions, 7 deletions
diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index d55693b8af46..087e05570a5d 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -305,7 +305,14 @@ private:
{
const ScAddress& s = rRange.aStart;
const ScAddress& e = rRange.aEnd;
- return s.Tab() + s.Col() + s.Row() + e.Tab() + e.Col() + e.Row();
+ size_t hash = 17;
+ hash = hash * 37 + s.Tab();
+ hash = hash * 37 + s.Col();
+ hash = hash * 37 + s.Row();
+ hash = hash * 37 + e.Tab();
+ hash = hash * 37 + e.Col();
+ hash = hash * 37 + e.Row();
+ return hash;
}
};
diff --git a/sc/source/core/data/dpresfilter.cxx b/sc/source/core/data/dpresfilter.cxx
index c4102824fe1f..2efb4563f8ee 100644
--- a/sc/source/core/data/dpresfilter.cxx
+++ b/sc/source/core/data/dpresfilter.cxx
@@ -13,6 +13,7 @@
#include <unotools/charclass.hxx>
#include <rtl/math.hxx>
#include <sal/log.hxx>
+#include <boost/functional/hash.hpp>
#include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
#include <com/sun/star/uno/Sequence.hxx>
@@ -28,8 +29,10 @@ ScDPResultFilterContext::ScDPResultFilterContext() :
size_t ScDPResultTree::NamePairHash::operator() (const NamePairType& rPair) const
{
- OUStringHash aHash;
- return aHash(rPair.first) + aHash(rPair.second);
+ std::size_t seed = 0;
+ boost::hash_combine(seed, rPair.first.hashCode());
+ boost::hash_combine(seed, rPair.second.hashCode());
+ return seed;
}
ScDPResultTree::DimensionNode::DimensionNode() {}
diff --git a/sc/source/ui/view/spellcheckcontext.cxx b/sc/source/ui/view/spellcheckcontext.cxx
index 5f03da7d882c..867dc26f5738 100644
--- a/sc/source/ui/view/spellcheckcontext.cxx
+++ b/sc/source/ui/view/spellcheckcontext.cxx
@@ -8,15 +8,16 @@
*/
#include <spellcheckcontext.hxx>
+#include <boost/functional/hash.hpp>
namespace sc {
size_t SpellCheckContext::CellPos::Hash::operator() (const CellPos& rPos) const
{
- size_t nVal = rPos.mnCol;
- nVal = nVal << 4;
- nVal += rPos.mnRow;
- return nVal;
+ std::size_t seed = 0;
+ boost::hash_combine(seed, rPos.mnCol);
+ boost::hash_combine(seed, rPos.mnRow);
+ return seed;
}
SpellCheckContext::CellPos::CellPos() : mnCol(0), mnRow(0) {}