mtklein 2014-07-11 08:42:17 -07:00 коммит произвёл Commit bot
Родитель 00a8fae0ce
Коммит 19fcc7494e
2 изменённых файлов: 19 добавлений и 32 удалений

Просмотреть файл

@ -62,12 +62,18 @@ public:
* @return hash result
*/
static uint32_t Murmur3(const uint32_t* data, size_t bytes, uint32_t seed=0) {
// Use may_alias to remind the compiler we're intentionally violating strict aliasing,
// and so not to apply strict-aliasing-based optimizations.
typedef uint32_t SK_ATTRIBUTE(may_alias) aliased_uint32_t;
const aliased_uint32_t* safe_data = (const aliased_uint32_t*)data;
SkASSERTF(SkIsAlign4(bytes), "Expected 4-byte multiple, got %zu", bytes);
const size_t words = bytes/4;
uint32_t hash = seed;
for (size_t i = 0; i < words; i++) {
uint32_t k = data[i];
uint32_t k = safe_data[i];
k *= 0xcc9e2d51;
k = (k << 15) | (k >> 17);
k *= 0x1b873593;
@ -95,6 +101,11 @@ public:
* @return checksum result
*/
static uint32_t Compute(const uint32_t* data, size_t size) {
// Use may_alias to remind the compiler we're intentionally violating strict aliasing,
// and so not to apply strict-aliasing-based optimizations.
typedef uint32_t SK_ATTRIBUTE(may_alias) aliased_uint32_t;
const aliased_uint32_t* safe_data = (const aliased_uint32_t*)data;
SkASSERT(SkIsAlign4(size));
/*
@ -104,7 +115,7 @@ public:
* sizeof()).
*/
uintptr_t result = 0;
const uintptr_t* ptr = reinterpret_cast<const uintptr_t*>(data);
const uintptr_t* ptr = reinterpret_cast<const uintptr_t*>(safe_data);
/*
* count the number of quad element chunks. This takes into account
@ -120,10 +131,10 @@ public:
}
size &= ((sizeof(uintptr_t) << 2) - 1);
data = reinterpret_cast<const uint32_t*>(ptr);
const uint32_t* stop = data + (size >> 2);
while (data < stop) {
result = Mash(result, *data++);
safe_data = reinterpret_cast<const aliased_uint32_t*>(ptr);
const aliased_uint32_t* stop = safe_data + (size >> 2);
while (safe_data < stop) {
result = Mash(result, *safe_data++);
}
/*

Просмотреть файл

@ -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;