summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-04-09 09:27:09 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-04-09 12:00:04 +0200
commit917fb3c1b09eb145551eae357a1220311261532a (patch)
treede1d4c9850acae03712de5afd145ebfbbb777f25 /vcl
parent98fc1401b4ee4573cf83ccd400cd2dc81848b7e7 (diff)
tdf#104878 speed up GfxLink compare
which shaves 5% off the rendering time Change-Id: Iab2a92088c5d1e8840a53ff57ab1a95ba5ec8e0a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91947 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/gdi/gfxlink.cxx48
1 files changed, 33 insertions, 15 deletions
diff --git a/vcl/source/gdi/gfxlink.cxx b/vcl/source/gdi/gfxlink.cxx
index 785d86d3be7f..9a3f6561be8f 100644
--- a/vcl/source/gdi/gfxlink.cxx
+++ b/vcl/source/gdi/gfxlink.cxx
@@ -24,6 +24,7 @@
#include <vcl/gfxlink.hxx>
#include <vcl/graphicfilter.hxx>
#include <memory>
+#include <boost/functional/hash.hpp>
GfxLink::GfxLink()
: meType(GfxLinkType::NONE)
@@ -34,6 +35,8 @@ GfxLink::GfxLink()
{
}
+
+
GfxLink::GfxLink(std::unique_ptr<sal_uInt8[]> pBuf, sal_uInt32 nSize, GfxLinkType nType)
: meType(nType)
, mnUserId(0)
@@ -46,26 +49,41 @@ GfxLink::GfxLink(std::unique_ptr<sal_uInt8[]> pBuf, sal_uInt32 nSize, GfxLinkTyp
"GfxLink::GfxLink(): empty/NULL buffer given");
}
-bool GfxLink::operator==( const GfxLink& rGfxLink ) const
+size_t GfxLink::GetHash() const
{
- bool bIsEqual = false;
-
- if ( ( mnSwapInDataSize == rGfxLink.mnSwapInDataSize ) && ( meType == rGfxLink.meType ) )
+ if (!maHash)
{
- const sal_uInt8* pSource = GetData();
- const sal_uInt8* pDest = rGfxLink.GetData();
- sal_uInt32 nSourceSize = GetDataSize();
- sal_uInt32 nDestSize = rGfxLink.GetDataSize();
- if ( pSource && pDest && ( nSourceSize == nDestSize ) )
- {
- bIsEqual = memcmp( pSource, pDest, nSourceSize ) == 0;
- }
- else if ( ( pSource == nullptr ) && ( pDest == nullptr ) )
- bIsEqual = true;
+ std::size_t seed = 0;
+ boost::hash_combine(seed, mnSwapInDataSize);
+ boost::hash_combine(seed, meType);
+ const sal_uInt8* pData = GetData();
+ if (pData)
+ seed += boost::hash_range(pData, pData + GetDataSize());
+ maHash = seed;
+
}
- return bIsEqual;
+ return maHash;
}
+bool GfxLink::operator==( const GfxLink& rGfxLink ) const
+{
+ if (GetHash() != rGfxLink.GetHash())
+ return false;
+
+ if ( mnSwapInDataSize != rGfxLink.mnSwapInDataSize ||
+ meType != rGfxLink.meType )
+ return false;
+
+ const sal_uInt8* pSource = GetData();
+ const sal_uInt8* pDest = rGfxLink.GetData();
+ if ( pSource == pDest )
+ return true;
+ sal_uInt32 nSourceSize = GetDataSize();
+ sal_uInt32 nDestSize = rGfxLink.GetDataSize();
+ if ( pSource && pDest && ( nSourceSize == nDestSize ) )
+ return (memcmp( pSource, pDest, nSourceSize ) == 0);
+ return false;
+}
bool GfxLink::IsNative() const
{