diff options
-rw-r--r-- | include/vcl/gfxlink.hxx | 5 | ||||
-rw-r--r-- | vcl/source/gdi/gfxlink.cxx | 48 |
2 files changed, 36 insertions, 17 deletions
diff --git a/include/vcl/gfxlink.hxx b/include/vcl/gfxlink.hxx index 0376149f7025..0e116234fcb5 100644 --- a/include/vcl/gfxlink.hxx +++ b/include/vcl/gfxlink.hxx @@ -62,9 +62,8 @@ class VCL_DLLPUBLIC GfxLink private: GfxLinkType meType; sal_uInt32 mnUserId; - mutable std::shared_ptr<sal_uInt8> mpSwapInData; - + mutable size_t maHash; sal_uInt32 mnSwapInDataSize; MapMode maPrefMapMode; Size maPrefSize; @@ -82,6 +81,8 @@ public: GfxLinkType GetType() const { return meType;} + size_t GetHash() const; + void SetUserId( sal_uInt32 nUserId ) { mnUserId = nUserId; } sal_uInt32 GetUserId() const { return mnUserId; } 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 { |