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 /sdext/source | |
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 'sdext/source')
-rw-r--r-- | sdext/source/pdfimport/inc/pdfihelper.hxx | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/sdext/source/pdfimport/inc/pdfihelper.hxx b/sdext/source/pdfimport/inc/pdfihelper.hxx index 072a5bd01d50..4a7fd569688e 100644 --- a/sdext/source/pdfimport/inc/pdfihelper.hxx +++ b/sdext/source/pdfimport/inc/pdfihelper.hxx @@ -82,13 +82,14 @@ namespace pdfi { size_t operator()(const FontAttributes& rFont ) const { - return static_cast<size_t>(rFont.familyName.hashCode()) - ^ size_t(rFont.isBold ? 0xd47be593 : 0) - ^ size_t(rFont.isItalic ? 0x1efd51a1 : 0) - ^ size_t(rFont.isUnderline ? 0xf6bd325a : 0) - ^ size_t(rFont.isOutline ? 0x12345678 : 0) - ^ size_t(rFont.size) - ; + std::size_t seed = 0; + boost::hash_combine(seed, rFont.familyName.hashCode()); + boost::hash_combine(seed, rFont.isBold); + boost::hash_combine(seed, rFont.isItalic); + boost::hash_combine(seed, rFont.isUnderline); + boost::hash_combine(seed, rFont.isOutline); + boost::hash_combine(seed, rFont.size); + return seed; } }; @@ -184,31 +185,32 @@ namespace pdfi { size_t operator()(const GraphicsContext& rGC ) const { - return boost::hash_value(rGC.LineColor.Red) - ^ boost::hash_value(rGC.LineColor.Green) - ^ boost::hash_value(rGC.LineColor.Blue) - ^ boost::hash_value(rGC.LineColor.Alpha) - ^ boost::hash_value(rGC.FillColor.Red) - ^ boost::hash_value(rGC.FillColor.Green) - ^ boost::hash_value(rGC.FillColor.Blue) - ^ boost::hash_value(rGC.FillColor.Alpha) - ^ boost::hash_value(rGC.LineJoin) - ^ boost::hash_value(rGC.LineCap) - ^ boost::hash_value(rGC.BlendMode) - ^ boost::hash_value(rGC.LineWidth) - ^ boost::hash_value(rGC.Flatness) - ^ boost::hash_value(rGC.MiterLimit) - ^ rGC.DashArray.size() - ^ boost::hash_value(rGC.FontId) - ^ boost::hash_value(rGC.TextRenderMode) - ^ boost::hash_value(rGC.Transformation.get( 0, 0 )) - ^ boost::hash_value(rGC.Transformation.get( 1, 0 )) - ^ boost::hash_value(rGC.Transformation.get( 0, 1 )) - ^ boost::hash_value(rGC.Transformation.get( 1, 1 )) - ^ boost::hash_value(rGC.Transformation.get( 0, 2 )) - ^ boost::hash_value(rGC.Transformation.get( 1, 2 )) - ^ boost::hash_value(rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0) - ; + std::size_t seed = 0; + boost::hash_combine(seed, rGC.LineColor.Red); + boost::hash_combine(seed, rGC.LineColor.Green); + boost::hash_combine(seed, rGC.LineColor.Blue); + boost::hash_combine(seed, rGC.LineColor.Alpha); + boost::hash_combine(seed, rGC.FillColor.Red); + boost::hash_combine(seed, rGC.FillColor.Green); + boost::hash_combine(seed, rGC.FillColor.Blue); + boost::hash_combine(seed, rGC.FillColor.Alpha); + boost::hash_combine(seed, rGC.LineJoin); + boost::hash_combine(seed, rGC.LineCap); + boost::hash_combine(seed, rGC.BlendMode); + boost::hash_combine(seed, rGC.LineWidth); + boost::hash_combine(seed, rGC.Flatness); + boost::hash_combine(seed, rGC.MiterLimit); + boost::hash_combine(seed, rGC.DashArray.size()); + boost::hash_combine(seed, rGC.FontId); + boost::hash_combine(seed, rGC.TextRenderMode); + boost::hash_combine(seed, rGC.Transformation.get( 0, 0 )); + boost::hash_combine(seed, rGC.Transformation.get( 1, 0 )); + boost::hash_combine(seed, rGC.Transformation.get( 0, 1 )); + boost::hash_combine(seed, rGC.Transformation.get( 1, 1 )); + boost::hash_combine(seed, rGC.Transformation.get( 0, 2 )); + boost::hash_combine(seed, rGC.Transformation.get( 1, 2 )); + boost::hash_combine(seed, rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0); + return seed; } }; |