Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_HASH_H_ | 5 #ifndef BASE_HASH_H_ |
| 6 #define BASE_HASH_H_ | 6 #define BASE_HASH_H_ |
| 7 | 7 |
| 8 #include <limits> | |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" | |
| 12 | 14 |
| 13 namespace base { | 15 namespace base { |
| 14 | 16 |
| 15 // From http://www.azillionmonkeys.com/qed/hash.html | 17 // WARNING: This hash function should not be used for any cryptographic purpose. |
| 16 // This is the hash used on WebCore/platform/stringhash | 18 BASE_EXPORT uint32 SuperFastHash(const char* data, int len); |
| 17 BASE_EXPORT uint32 SuperFastHash(const char * data, int len); | |
| 18 | 19 |
| 20 // Computes the hash of a string |key| of a given |length|. |key| does not need | |
| 21 // to be null-terminated, and may contain null bytes. | |
| 22 // WARNING: This hash function should not be used for any cryptographic purpose. | |
| 19 inline uint32 Hash(const char* key, size_t length) { | 23 inline uint32 Hash(const char* key, size_t length) { |
| 24 if (length > std::numeric_limits<int>::max()) { | |
| 25 NOTREACHED(); | |
| 26 return 0; | |
| 27 } | |
| 20 return SuperFastHash(key, static_cast<int>(length)); | 28 return SuperFastHash(key, static_cast<int>(length)); |
| 21 } | 29 } |
| 22 | 30 |
| 31 // Computes the hash of a string |key|. | |
| 32 // WARNING: This hash function should not be used for any cryptographic purpose. | |
| 23 inline uint32 Hash(const std::string& key) { | 33 inline uint32 Hash(const std::string& key) { |
| 24 if (key.empty()) | 34 return Hash(key.data(), key.size()); |
|
Matt Giuca
2014/02/27 05:25:29
I fixed the static_cast here too (by calling throu
| |
| 25 return 0; | |
| 26 return SuperFastHash(key.data(), static_cast<int>(key.size())); | |
| 27 } | 35 } |
| 28 | 36 |
| 29 } // namespace base | 37 } // namespace base |
| 30 | 38 |
| 31 #endif // BASE_HASH_H_ | 39 #endif // BASE_HASH_H_ |
| OLD | NEW |