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 | 5 |
| 6 // | 6 // |
| 7 // Deal with the differences between Microsoft and GNU implemenations | 7 // Deal with the differences between Microsoft and GNU implemenations |
| 8 // of hash_map. Allows all platforms to use |base::hash_map| and | 8 // of hash_map. Allows all platforms to use |base::hash_map| and |
| 9 // |base::hash_set|. | 9 // |base::hash_set|. |
| 10 // eg: | 10 // eg: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "base/basictypes.h" | 26 #include "base/basictypes.h" |
| 27 #include "base/strings/string16.h" | 27 #include "base/strings/string16.h" |
| 28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
| 29 | 29 |
| 30 #if defined(COMPILER_MSVC) | 30 #if defined(COMPILER_MSVC) |
| 31 #include <unordered_map> | 31 #include <unordered_map> |
| 32 #include <unordered_set> | 32 #include <unordered_set> |
| 33 | 33 |
| 34 #define BASE_HASH_NAMESPACE std | 34 #define BASE_HASH_NAMESPACE std |
| 35 | 35 |
| 36 #elif defined(COMPILER_GCC) | 36 #elif defined(COMPILER_GCC) |
|
Fabrice (no longer in Chrome)
2014/11/05 12:33:05
This essentially does a hack for pre-C++11 headers
Nico
2014/11/05 17:30:10
And webview host, apparently. base/ is built as ho
| |
| 37 | 37 |
| 38 #define BASE_HASH_NAMESPACE base_hash | 38 #define BASE_HASH_NAMESPACE base_hash |
| 39 | 39 |
| 40 // This is a hack to disable the gcc 4.4 warning about hash_map and hash_set | 40 // This is a hack to disable the gcc 4.4 warning about hash_map and hash_set |
| 41 // being deprecated. We can get rid of this when we upgrade to VS2008 and we | 41 // being deprecated. We can get rid of this when we upgrade to VS2008 and we |
| 42 // can use <tr1/unordered_map> and <tr1/unordered_set>. | 42 // can use <tr1/unordered_map> and <tr1/unordered_set>. |
| 43 #ifdef __DEPRECATED | 43 #ifdef __DEPRECATED |
| 44 #define CHROME_OLD__DEPRECATED __DEPRECATED | 44 #define CHROME_OLD__DEPRECATED __DEPRECATED |
| 45 #undef __DEPRECATED | 45 #undef __DEPRECATED |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 #if defined(OS_ANDROID) | |
| 49 #include <hash_map> | |
| 50 #include <hash_set> | |
| 51 #define BASE_HASH_IMPL_NAMESPACE std | |
| 52 #else | |
| 53 #include <ext/hash_map> | 48 #include <ext/hash_map> |
| 54 #include <ext/hash_set> | 49 #include <ext/hash_set> |
| 55 #define BASE_HASH_IMPL_NAMESPACE __gnu_cxx | 50 #define BASE_HASH_IMPL_NAMESPACE __gnu_cxx |
| 56 #endif | |
| 57 | 51 |
| 58 #include <string> | 52 #include <string> |
| 59 | 53 |
| 60 #ifdef CHROME_OLD__DEPRECATED | 54 #ifdef CHROME_OLD__DEPRECATED |
| 61 #define __DEPRECATED CHROME_OLD__DEPRECATED | 55 #define __DEPRECATED CHROME_OLD__DEPRECATED |
| 62 #undef CHROME_OLD__DEPRECATED | 56 #undef CHROME_OLD__DEPRECATED |
| 63 #endif | 57 #endif |
| 64 | 58 |
| 65 namespace BASE_HASH_NAMESPACE { | 59 namespace BASE_HASH_NAMESPACE { |
| 66 | 60 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 77 }; | 71 }; |
| 78 | 72 |
| 79 template<typename T> | 73 template<typename T> |
| 80 struct hash<T*> { | 74 struct hash<T*> { |
| 81 std::size_t operator()(T* value) const { | 75 std::size_t operator()(T* value) const { |
| 82 return BASE_HASH_IMPL_NAMESPACE::hash<uintptr_t>()( | 76 return BASE_HASH_IMPL_NAMESPACE::hash<uintptr_t>()( |
| 83 reinterpret_cast<uintptr_t>(value)); | 77 reinterpret_cast<uintptr_t>(value)); |
| 84 } | 78 } |
| 85 }; | 79 }; |
| 86 | 80 |
| 87 #if !defined(OS_ANDROID) | |
| 88 // The GNU C++ library provides identity hash functions for many integral types, | 81 // The GNU C++ library provides identity hash functions for many integral types, |
| 89 // but not for |long long|. This hash function will truncate if |size_t| is | 82 // but not for |long long|. This hash function will truncate if |size_t| is |
| 90 // narrower than |long long|. This is probably good enough for what we will | 83 // narrower than |long long|. This is probably good enough for what we will |
| 91 // use it for. | 84 // use it for. |
| 92 | 85 |
| 93 #define DEFINE_TRIVIAL_HASH(integral_type) \ | 86 #define DEFINE_TRIVIAL_HASH(integral_type) \ |
| 94 template<> \ | 87 template<> \ |
| 95 struct hash<integral_type> { \ | 88 struct hash<integral_type> { \ |
| 96 std::size_t operator()(integral_type value) const { \ | 89 std::size_t operator()(integral_type value) const { \ |
| 97 return static_cast<std::size_t>(value); \ | 90 return static_cast<std::size_t>(value); \ |
| 98 } \ | 91 } \ |
| 99 } | 92 } |
| 100 | 93 |
| 101 DEFINE_TRIVIAL_HASH(long long); | 94 DEFINE_TRIVIAL_HASH(long long); |
| 102 DEFINE_TRIVIAL_HASH(unsigned long long); | 95 DEFINE_TRIVIAL_HASH(unsigned long long); |
| 103 | 96 |
| 104 #undef DEFINE_TRIVIAL_HASH | 97 #undef DEFINE_TRIVIAL_HASH |
| 105 #endif // !defined(OS_ANDROID) | |
| 106 | 98 |
| 107 // Implement string hash functions so that strings of various flavors can | 99 // Implement string hash functions so that strings of various flavors can |
| 108 // be used as keys in STL maps and sets. The hash algorithm comes from the | 100 // be used as keys in STL maps and sets. The hash algorithm comes from the |
| 109 // GNU C++ library, in <tr1/functional>. It is duplicated here because GCC | 101 // GNU C++ library, in <tr1/functional>. It is duplicated here because GCC |
| 110 // versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI | 102 // versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI |
| 111 // is disabled, as it is in our build. | 103 // is disabled, as it is in our build. |
| 112 | 104 |
| 113 #define DEFINE_STRING_HASH(string_type) \ | 105 #define DEFINE_STRING_HASH(string_type) \ |
| 114 template<> \ | 106 template<> \ |
| 115 struct hash<string_type> { \ | 107 struct hash<string_type> { \ |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 return base::HashPair(value.first, value.second); | 311 return base::HashPair(value.first, value.second); |
| 320 } | 312 } |
| 321 }; | 313 }; |
| 322 | 314 |
| 323 } | 315 } |
| 324 | 316 |
| 325 #undef DEFINE_PAIR_HASH_FUNCTION_START | 317 #undef DEFINE_PAIR_HASH_FUNCTION_START |
| 326 #undef DEFINE_PAIR_HASH_FUNCTION_END | 318 #undef DEFINE_PAIR_HASH_FUNCTION_END |
| 327 | 319 |
| 328 #endif // BASE_CONTAINERS_HASH_TABLES_H_ | 320 #endif // BASE_CONTAINERS_HASH_TABLES_H_ |
| OLD | NEW |