BUG=skia:
R=reed@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/
376183004
#include "Benchmark.h"
#include "SkCanvas.h"
+#include "SkChecksum.h"
#include "SkFontHost.h"
#include "SkPaint.h"
#include "SkString.h"
return value ^ (value >> 8);
}
-static uint32_t hasher2(uint32_t h) {
- h ^= h >> 16;
- h *= 0x85ebca6b;
- h ^= h >> 13;
- h *= 0xc2b2ae35;
- h ^= h >> 16;
-
- h ^= (h >> 8);
- return h;
-}
-
static const struct {
const char* fName;
HasherProc fHasher;
} gRec[] = {
{ "hasher0", hasher0 },
- { "hasher2", hasher2 },
+ { "hasher2", SkChecksum::Mix },
};
#define kMaxHashBits 12
}
public:
+ /**
+ * uint32_t -> uint32_t hash, useful for when you're about to trucate this hash but you
+ * suspect its low bits aren't well mixed.
+ *
+ * This is the Murmur3 finalizer.
+ */
+ static uint32_t Mix(uint32_t hash) {
+ hash ^= hash >> 16;
+ hash *= 0x85ebca6b;
+ hash ^= hash >> 13;
+ hash *= 0xc2b2ae35;
+ hash ^= hash >> 16;
+ return hash;
+ }
/**
* Calculate 32-bit Murmur hash (murmur3).
* @return hash result
*/
static uint32_t Murmur3(const uint32_t* data, size_t bytes, uint32_t seed=0) {
- SkASSERT(SkIsAlign4(bytes));
+ SkASSERTF(SkIsAlign4(bytes), "Expected 4-byte multiple, got %zu", bytes);
const size_t words = bytes/4;
uint32_t hash = seed;
hash += 0xe6546b64;
}
hash ^= bytes;
- hash ^= hash >> 16;
- hash *= 0x85ebca6b;
- hash ^= hash >> 13;
- hash *= 0xc2b2ae35;
- hash ^= hash >> 16;
- return hash;
+ return Mix(hash);
}
/**
#include "SkImageFilter.h"
#include "SkBitmap.h"
+#include "SkChecksum.h"
#include "SkDevice.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
}
#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) {
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;
* found in the LICENSE file.
*/
+#include "SkChecksum.h"
#include "SkScaledImageCache.h"
#include "SkMipMap.h"
#include "SkPixelRef.h"
return reinterpret_cast<SkScaledImageCache::Rec*>(id);
}
- // Implemented from en.wikipedia.org/wiki/MurmurHash.
-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;
-}
-
struct SkScaledImageCache::Key {
Key(uint32_t genID,
SkScalar scaleX,
, fScaleX(scaleX)
, fScaleY(scaleY)
, fBounds(bounds) {
- fHash = compute_hash(&fGenID, 7);
+ fHash = SkChecksum::Murmur3(&fGenID, 28);
}
bool operator<(const Key& other) const {