diff options
Diffstat (limited to 'chromium/base/hash.h')
-rw-r--r-- | chromium/base/hash.h | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/chromium/base/hash.h b/chromium/base/hash.h index cf8ea3a26e4..e46f6ac2484 100644 --- a/chromium/base/hash.h +++ b/chromium/base/hash.h @@ -5,25 +5,32 @@ #ifndef BASE_HASH_H_ #define BASE_HASH_H_ +#include <limits> #include <string> #include "base/base_export.h" #include "base/basictypes.h" +#include "base/logging.h" namespace base { -// From http://www.azillionmonkeys.com/qed/hash.html -// This is the hash used on WebCore/platform/stringhash -BASE_EXPORT uint32 SuperFastHash(const char * data, int len); +// WARNING: This hash function should not be used for any cryptographic purpose. +BASE_EXPORT uint32 SuperFastHash(const char* data, int len); -inline uint32 Hash(const char* key, size_t length) { - return SuperFastHash(key, static_cast<int>(length)); +// Computes a hash of a memory buffer |data| of a given |length|. +// WARNING: This hash function should not be used for any cryptographic purpose. +inline uint32 Hash(const char* data, size_t length) { + if (length > static_cast<size_t>(std::numeric_limits<int>::max())) { + NOTREACHED(); + return 0; + } + return SuperFastHash(data, 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())); +// Computes a hash of a string |str|. +// WARNING: This hash function should not be used for any cryptographic purpose. +inline uint32 Hash(const std::string& str) { + return Hash(str.data(), str.size()); } } // namespace base |