aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-07-10 14:10:45 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-10 14:10:47 -0700
commit53d435990bdb4d14df78013da45a9364d0287ebe (patch)
tree52ba2dff9d429e069fe07c63a8cfa6960c32327e
parentb17c764f852c04d84f8fbbc3c82eefb8c7665217 (diff)
Slim Skia down to just one murmur3 implementation.
-rw-r--r--src/core/SkChecksum.h8
-rw-r--r--src/core/SkImageFilter.cpp28
-rw-r--r--tests/ChecksumTest.cpp6
3 files changed, 12 insertions, 30 deletions
diff --git a/src/core/SkChecksum.h b/src/core/SkChecksum.h
index fe1e9584a2..daf87cf62e 100644
--- a/src/core/SkChecksum.h
+++ b/src/core/SkChecksum.h
@@ -51,6 +51,10 @@ 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.
@@ -61,7 +65,7 @@ public:
* @param seed Initial hash seed. (optional)
* @return hash result
*/
- static uint32_t Murmur3(const uint32_t* data, size_t bytes, uint32_t seed=0) {
+ static uint32_t Murmur3(const FourByteAligned* data, size_t bytes, uint32_t seed=0) {
SkASSERTF(SkIsAlign4(bytes), "Expected 4-byte multiple, got %zu", bytes);
const size_t words = bytes/4;
@@ -94,7 +98,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 uint32_t* data, size_t size) {
+ static uint32_t Compute(const FourByteAligned* data, size_t size) {
SkASSERT(SkIsAlign4(size));
/*
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 64603b4cb5..8a0e734b24 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -8,6 +8,7 @@
#include "SkImageFilter.h"
#include "SkBitmap.h"
+#include "SkChecksum.h"
#include "SkDevice.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
@@ -334,31 +335,6 @@ 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) {
@@ -381,7 +357,7 @@ private:
return v.fKey;
}
static uint32_t Hash(Key key) {
- return compute_hash(reinterpret_cast<const uint32_t*>(&key), sizeof(Key) / sizeof(uint32_t));
+ return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(Key));
}
};
SkTDynamicHash<Value, Key> fData;
diff --git a/tests/ChecksumTest.cpp b/tests/ChecksumTest.cpp
index 6248678043..923f303509 100644
--- a/tests/ChecksumTest.cpp
+++ b/tests/ChecksumTest.cpp
@@ -11,13 +11,15 @@
// Murmur3 has an optional third seed argument, so we wrap it to fit a uniform type.
-static uint32_t murmur_noseed(const uint32_t* d, size_t l) { return SkChecksum::Murmur3(d, l); }
+static uint32_t murmur_noseed(const SkChecksum::FourByteAligned* d, size_t l) {
+ return SkChecksum::Murmur3(d, l);
+}
#define ASSERT(x) REPORTER_ASSERT(r, x)
DEF_TEST(Checksum, r) {
// Algorithms to test. They're currently all uint32_t(const uint32_t*, size_t).
- typedef uint32_t(*algorithmProc)(const uint32_t*, size_t);
+ typedef uint32_t(*algorithmProc)(const SkChecksum::FourByteAligned*, size_t);
const algorithmProc kAlgorithms[] = { &SkChecksum::Compute, &murmur_noseed };
// Put 128 random bytes into two identical buffers. Any multiple of 4 will do.