diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkChecksum.h | 8 | ||||
-rw-r--r-- | src/core/SkImageFilter.cpp | 28 |
2 files changed, 28 insertions, 8 deletions
diff --git a/src/core/SkChecksum.h b/src/core/SkChecksum.h index daf87cf62e..fe1e9584a2 100644 --- a/src/core/SkChecksum.h +++ b/src/core/SkChecksum.h @@ -51,10 +51,6 @@ public: return hash; } - // Remind compiler that our users will be intentionally violating strict aliasing by casting - // their data to const uint32_t*, so don't apply any strict-aliasing-based optimizations. - typedef uint32_t SK_ATTRIBUTE(may_alias) FourByteAligned; - /** * Calculate 32-bit Murmur hash (murmur3). * This should take 2-3x longer than SkChecksum::Compute, but is a considerably better hash. @@ -65,7 +61,7 @@ public: * @param seed Initial hash seed. (optional) * @return hash result */ - static uint32_t Murmur3(const FourByteAligned* data, size_t bytes, uint32_t seed=0) { + static uint32_t Murmur3(const uint32_t* data, size_t bytes, uint32_t seed=0) { SkASSERTF(SkIsAlign4(bytes), "Expected 4-byte multiple, got %zu", bytes); const size_t words = bytes/4; @@ -98,7 +94,7 @@ public: * @param size Size of the data block in bytes. Must be a multiple of 4. * @return checksum result */ - static uint32_t Compute(const FourByteAligned* data, size_t size) { + static uint32_t Compute(const uint32_t* data, size_t size) { SkASSERT(SkIsAlign4(size)); /* diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 8a0e734b24..64603b4cb5 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -8,7 +8,6 @@ #include "SkImageFilter.h" #include "SkBitmap.h" -#include "SkChecksum.h" #include "SkDevice.h" #include "SkReadBuffer.h" #include "SkWriteBuffer.h" @@ -335,6 +334,31 @@ bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, } #endif +static uint32_t compute_hash(const uint32_t* data, int count) { + uint32_t hash = 0; + + for (int i = 0; i < count; ++i) { + uint32_t k = data[i]; + k *= 0xcc9e2d51; + k = (k << 15) | (k >> 17); + k *= 0x1b873593; + + hash ^= k; + hash = (hash << 13) | (hash >> 19); + hash *= 5; + hash += 0xe6546b64; + } + + // hash ^= size; + hash ^= hash >> 16; + hash *= 0x85ebca6b; + hash ^= hash >> 13; + hash *= 0xc2b2ae35; + hash ^= hash >> 16; + + return hash; +} + class CacheImpl : public SkImageFilter::Cache { public: explicit CacheImpl(int minChildren) : fMinChildren(minChildren) { @@ -357,7 +381,7 @@ private: return v.fKey; } static uint32_t Hash(Key key) { - return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key)); + return compute_hash(reinterpret_cast<const uint32_t*>(&key), sizeof(Key) / sizeof(uint32_t)); } }; SkTDynamicHash<Value, Key> fData; |