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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 | 12 |
| 13 #ifdef __cplusplus | |
|
rvargas (doing something else)
2014/02/27 04:11:20
Do we need this?
Matt Giuca
2014/02/27 04:24:09
Assuming you mean #ifdef __cplusplus as opposed to
| |
| 14 extern "C" { | |
| 15 #endif | |
| 16 | |
| 17 // Definition in base/third_party/superfasthash/superfasthash.c. (Third-party | |
| 18 // code did not come with its own header file, so declaring the function here.) | |
| 19 uint32_t SuperFastHash(const char* data, int len); | |
| 20 | |
| 21 #ifdef __cplusplus | |
| 22 } | |
| 23 #endif | |
| 24 | |
| 13 namespace base { | 25 namespace base { |
| 14 | 26 |
|
jln (very slow on Chromium)
2014/02/27 04:37:17
Please, make it very clear that none of these shou
Matt Giuca
2014/02/27 05:25:29
Done.
| |
| 15 // From http://www.azillionmonkeys.com/qed/hash.html | 27 BASE_EXPORT uint32 SuperFastHash(const char* data, int len); |
| 16 // This is the hash used on WebCore/platform/stringhash | |
| 17 BASE_EXPORT uint32 SuperFastHash(const char * data, int len); | |
| 18 | 28 |
| 19 inline uint32 Hash(const char* key, size_t length) { | 29 inline uint32 Hash(const char* key, size_t length) { |
| 20 return SuperFastHash(key, static_cast<int>(length)); | 30 return SuperFastHash(key, static_cast<int>(length)); |
|
jln (very slow on Chromium)
2014/02/27 04:37:17
This cast is implementation defined for values str
Matt Giuca
2014/02/27 05:25:29
Done.
(Note that the existing implementation does
| |
| 21 } | 31 } |
| 22 | 32 |
| 23 inline uint32 Hash(const std::string& key) { | 33 inline uint32 Hash(const std::string& key) { |
| 24 if (key.empty()) | 34 if (key.empty()) |
| 25 return 0; | 35 return 0; |
| 26 return SuperFastHash(key.data(), static_cast<int>(key.size())); | 36 return SuperFastHash(key.data(), static_cast<int>(key.size())); |
| 27 } | 37 } |
| 28 | 38 |
| 29 } // namespace base | 39 } // namespace base |
| 30 | 40 |
| 31 #endif // BASE_HASH_H_ | 41 #endif // BASE_HASH_H_ |
| OLD | NEW |