diff options
author | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-01 00:55:09 +0000 |
---|---|---|
committer | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-01 00:55:09 +0000 |
commit | 51ddf72550374b626eb2ea3239ca13f04c8eb2b7 (patch) | |
tree | d9f20bad2e99049d57c3d9350cd5a6ce72952cff /net/disk_cache | |
parent | 5731e121244fb91b97b37daefc1b59b27387b050 (diff) | |
download | chromium_src-51ddf72550374b626eb2ea3239ca13f04c8eb2b7.zip chromium_src-51ddf72550374b626eb2ea3239ca13f04c8eb2b7.tar.gz chromium_src-51ddf72550374b626eb2ea3239ca13f04c8eb2b7.tar.bz2 |
Move hash.h/cc from net to base.
Review URL: https://chromiumcodereview.appspot.com/10920026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@154554 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/backend_impl.cc | 8 | ||||
-rw-r--r-- | net/disk_cache/disk_cache_perftest.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/entry_impl.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/hash.cc | 73 | ||||
-rw-r--r-- | net/disk_cache/hash.h | 31 | ||||
-rw-r--r-- | net/disk_cache/storage_block-inl.h | 4 |
6 files changed, 10 insertions, 114 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index ffbe1f5..b2527ec 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -8,6 +8,7 @@ #include "base/bind_helpers.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/hash.h" #include "base/message_loop.h" #include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" @@ -26,7 +27,6 @@ #include "net/disk_cache/errors.h" #include "net/disk_cache/experiments.h" #include "net/disk_cache/file.h" -#include "net/disk_cache/hash.h" #include "net/disk_cache/mem_backend_impl.h" // This has to be defined before including histogram_macros.h from this file. @@ -665,7 +665,7 @@ void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { if (disabled_) return; - uint32 hash = Hash(key); + uint32 hash = base::Hash(key); bool error; EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); if (cache_entry) { @@ -681,7 +681,7 @@ EntryImpl* BackendImpl::OpenEntryImpl(const std::string& key) { return NULL; TimeTicks start = TimeTicks::Now(); - uint32 hash = Hash(key); + uint32 hash = base::Hash(key); Trace("Open hash 0x%x", hash); bool error; @@ -714,7 +714,7 @@ EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) { return NULL; TimeTicks start = TimeTicks::Now(); - uint32 hash = Hash(key); + uint32 hash = base::Hash(key); Trace("Create hash 0x%x", hash); scoped_refptr<EntryImpl> parent; diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc index 40a7527..e6b7dce 100644 --- a/net/disk_cache/disk_cache_perftest.cc +++ b/net/disk_cache/disk_cache_perftest.cc @@ -7,6 +7,7 @@ #include "base/basictypes.h" #include "base/bind.h" #include "base/bind_helpers.h" +#include "base/hash.h" #include "base/perftimer.h" #include "base/string_util.h" #include "base/threading/thread.h" @@ -20,7 +21,6 @@ #include "net/disk_cache/disk_cache.h" #include "net/disk_cache/disk_cache_test_base.h" #include "net/disk_cache/disk_cache_test_util.h" -#include "net/disk_cache/hash.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -152,7 +152,7 @@ TEST_F(DiskCacheTest, Hash) { PerfTimeLogger timer("Hash disk cache keys"); for (int i = 0; i < 300000; i++) { std::string key = GenerateKey(true); - disk_cache::Hash(key); + base::Hash(key); } timer.Done(); } diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index e4eb75a..37df0d7 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -4,6 +4,7 @@ #include "net/disk_cache/entry_impl.h" +#include "base/hash.h" #include "base/message_loop.h" #include "base/metrics/histogram.h" #include "base/string_util.h" @@ -12,7 +13,6 @@ #include "net/disk_cache/backend_impl.h" #include "net/disk_cache/bitmap.h" #include "net/disk_cache/cache_util.h" -#include "net/disk_cache/hash.h" #include "net/disk_cache/histogram_macros.h" #include "net/disk_cache/net_log_parameters.h" #include "net/disk_cache/sparse_control.h" @@ -616,7 +616,7 @@ bool EntryImpl::DataSanityCheck() { if (!key_addr.is_initialized() && stored->key[stored->key_len]) return false; - if (stored->hash != Hash(GetKey())) + if (stored->hash != base::Hash(GetKey())) return false; for (int i = 0; i < kNumStreams; i++) { diff --git a/net/disk_cache/hash.cc b/net/disk_cache/hash.cc deleted file mode 100644 index 78634b6..0000000 --- a/net/disk_cache/hash.cc +++ /dev/null @@ -1,73 +0,0 @@ -// From http://www.azillionmonkeys.com/qed/hash.html - -#include "net/disk_cache/hash.h" - -typedef uint32 uint32_t; -typedef uint16 uint16_t; - -namespace disk_cache { - -#undef get16bits -#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ - || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) -#define get16bits(d) (*((const uint16_t *) (d))) -#endif - -#if !defined (get16bits) -#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\ - +(uint32_t)(((const uint8_t *)(d))[0]) ) -#endif - -uint32 SuperFastHash(const char * data, int len) { - uint32_t hash = len, tmp; - int rem; - - if (len <= 0 || data == NULL) - return 0; - - rem = len & 3; - len >>= 2; - - /* Main loop */ - for (; len > 0; len--) { - hash += get16bits(data); - tmp = (get16bits(data + 2) << 11) ^ hash; - hash = (hash << 16) ^ tmp; - data += 2 * sizeof(uint16_t); - hash += hash >> 11; - } - - /* Handle end cases */ - switch (rem) { - case 3: - hash += get16bits(data); - hash ^= hash << 16; - - // Treat the final character as signed. This ensures all platforms behave - // consistently with the original x86 code. - hash ^= static_cast<signed char>(data[sizeof(uint16_t)]) << 18; - hash += hash >> 11; - break; - case 2: - hash += get16bits(data); - hash ^= hash << 11; - hash += hash >> 17; - break; - case 1: - hash += static_cast<signed char>(*data); - hash ^= hash << 10; - hash += hash >> 1; - } - - /* Force "avalanching" of final 127 bits */ - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 4; - hash += hash >> 17; - hash ^= hash << 25; - hash += hash >> 6; - - return hash; -} - -} // namespace disk_cache diff --git a/net/disk_cache/hash.h b/net/disk_cache/hash.h deleted file mode 100644 index 414a369..0000000 --- a/net/disk_cache/hash.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_DISK_CACHE_HASH_H__ -#define NET_DISK_CACHE_HASH_H__ - -#include <string> - -#include "base/basictypes.h" -#include "net/base/net_export.h" - -namespace disk_cache { - -// From http://www.azillionmonkeys.com/qed/hash.html -// This is the hash used on WebCore/platform/stringhash -NET_EXPORT_PRIVATE uint32 SuperFastHash(const char * data, int len); - -inline uint32 Hash(const char* key, size_t length) { - return SuperFastHash(key, static_cast<int>(length)); -} - -inline uint32 Hash(const std::string& key) { - if (key.empty()) - return 0; - return SuperFastHash(key.data(), static_cast<int>(key.size())); -} - -} // namespace disk_cache - -#endif // NET_DISK_CACHE_HASH_H__ diff --git a/net/disk_cache/storage_block-inl.h b/net/disk_cache/storage_block-inl.h index cc0b2aa..098cd74a 100644 --- a/net/disk_cache/storage_block-inl.h +++ b/net/disk_cache/storage_block-inl.h @@ -7,8 +7,8 @@ #include "net/disk_cache/storage_block.h" +#include "base/hash.h" #include "base/logging.h" -#include "net/disk_cache/hash.h" #include "net/disk_cache/trace.h" namespace disk_cache { @@ -167,7 +167,7 @@ template<typename T> void StorageBlock<T>::DeleteData() { } template<typename T> uint32 StorageBlock<T>::CalculateHash() const { - return Hash(reinterpret_cast<char*>(data_), offsetof(T, self_hash)); + return base::Hash(reinterpret_cast<char*>(data_), offsetof(T, self_hash)); } } // namespace disk_cache |