diff options
author | mtklein <mtklein@chromium.org> | 2015-10-21 11:53:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-21 11:53:27 -0700 |
commit | e71000f0dfe05f99d33b1309325dba4e089519b3 (patch) | |
tree | a5fd807c5fba3db8e459586d74fba50c9d8e148e | |
parent | b4a20767ee129ba47cee42e61252a9faec09c3a6 (diff) |
Move SkChecksum::Murmur3 out of the header.
As we use this more and more, we end up with more and more inline copies.
On my desktop, this makes Skia ~16K smaller.
Boy perf trybots would be neat.
BUG=skia:
Review URL: https://codereview.chromium.org/1415133003
-rw-r--r-- | gyp/core.gypi | 1 | ||||
-rw-r--r-- | include/private/SkChecksum.h | 39 | ||||
-rw-r--r-- | src/core/SkChecksum.cpp | 47 |
3 files changed, 49 insertions, 38 deletions
diff --git a/gyp/core.gypi b/gyp/core.gypi index c71ea317c7..85bc351372 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -65,6 +65,7 @@ '<(skia_src_path)/core/SkCachedData.cpp', '<(skia_src_path)/core/SkCanvas.cpp', '<(skia_src_path)/core/SkCanvasPriv.h', + '<(skia_src_path)/core/SkChecksum.cpp', '<(skia_src_path)/core/SkChunkAlloc.cpp', '<(skia_src_path)/core/SkClipStack.cpp', '<(skia_src_path)/core/SkColor.cpp', diff --git a/include/private/SkChecksum.h b/include/private/SkChecksum.h index cbc8a73a3e..4526416fc1 100644 --- a/include/private/SkChecksum.h +++ b/include/private/SkChecksum.h @@ -76,44 +76,7 @@ public: * @param seed Initial hash seed. (optional) * @return hash result */ - static uint32_t Murmur3(const void* 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; - typedef uint8_t SK_ATTRIBUTE(may_alias) aliased_uint8_t; - - // Handle 4 bytes at a time while possible. - const aliased_uint32_t* safe_data = (const aliased_uint32_t*)data; - const size_t words = bytes/4; - uint32_t hash = seed; - for (size_t i = 0; i < words; i++) { - uint32_t k = safe_data[i]; - k *= 0xcc9e2d51; - k = (k << 15) | (k >> 17); - k *= 0x1b873593; - - hash ^= k; - hash = (hash << 13) | (hash >> 19); - hash *= 5; - hash += 0xe6546b64; - } - - // Handle last 0-3 bytes. - const aliased_uint8_t* safe_tail = (const uint8_t*)(safe_data + words); - uint32_t k = 0; - switch (bytes & 3) { - case 3: k ^= safe_tail[2] << 16; - case 2: k ^= safe_tail[1] << 8; - case 1: k ^= safe_tail[0] << 0; - k *= 0xcc9e2d51; - k = (k << 15) | (k >> 17); - k *= 0x1b873593; - hash ^= k; - } - - hash ^= bytes; - return Mix(hash); - } + static uint32_t Murmur3(const void* data, size_t bytes, uint32_t seed=0); /** * Compute a 32-bit checksum for a given data block diff --git a/src/core/SkChecksum.cpp b/src/core/SkChecksum.cpp new file mode 100644 index 0000000000..4457eb4f99 --- /dev/null +++ b/src/core/SkChecksum.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkChecksum.h" + +uint32_t SkChecksum::Murmur3(const void* data, size_t bytes, uint32_t seed) { + // 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; + typedef uint8_t SK_ATTRIBUTE(may_alias) aliased_uint8_t; + + // Handle 4 bytes at a time while possible. + const aliased_uint32_t* safe_data = (const aliased_uint32_t*)data; + const size_t words = bytes/4; + uint32_t hash = seed; + for (size_t i = 0; i < words; i++) { + uint32_t k = safe_data[i]; + k *= 0xcc9e2d51; + k = (k << 15) | (k >> 17); + k *= 0x1b873593; + + hash ^= k; + hash = (hash << 13) | (hash >> 19); + hash *= 5; + hash += 0xe6546b64; + } + + // Handle last 0-3 bytes. + const aliased_uint8_t* safe_tail = (const uint8_t*)(safe_data + words); + uint32_t k = 0; + switch (bytes & 3) { + case 3: k ^= safe_tail[2] << 16; + case 2: k ^= safe_tail[1] << 8; + case 1: k ^= safe_tail[0] << 0; + k *= 0xcc9e2d51; + k = (k << 15) | (k >> 17); + k *= 0x1b873593; + hash ^= k; + } + + hash ^= bytes; + return SkChecksum::Mix(hash); +} |