Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1063)

Side by Side Diff: base/containers/hash_tables.h

Issue 691783003: [WIP NOT FOR COMMIT] Switch Android to libc++ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 27 matching lines...) Expand all
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 48 #define BASE_HASH_IMPL_NAMESPACE std
52 #else
53 #include <ext/hash_map> 49 #include <ext/hash_map>
54 #include <ext/hash_set> 50 #include <ext/hash_set>
51 #undef BASE_HASH_IMPL_NAMESPACE
55 #define BASE_HASH_IMPL_NAMESPACE __gnu_cxx 52 #define BASE_HASH_IMPL_NAMESPACE __gnu_cxx
56 #endif
57 53
58 #include <string> 54 #include <string>
59 55
60 #ifdef CHROME_OLD__DEPRECATED 56 #ifdef CHROME_OLD__DEPRECATED
61 #define __DEPRECATED CHROME_OLD__DEPRECATED 57 #define __DEPRECATED CHROME_OLD__DEPRECATED
62 #undef CHROME_OLD__DEPRECATED 58 #undef CHROME_OLD__DEPRECATED
63 #endif 59 #endif
64 60
65 namespace BASE_HASH_NAMESPACE { 61 namespace BASE_HASH_NAMESPACE {
66 62
(...skipping 10 matching lines...) Expand all
77 }; 73 };
78 74
79 template<typename T> 75 template<typename T>
80 struct hash<T*> { 76 struct hash<T*> {
81 std::size_t operator()(T* value) const { 77 std::size_t operator()(T* value) const {
82 return BASE_HASH_IMPL_NAMESPACE::hash<uintptr_t>()( 78 return BASE_HASH_IMPL_NAMESPACE::hash<uintptr_t>()(
83 reinterpret_cast<uintptr_t>(value)); 79 reinterpret_cast<uintptr_t>(value));
84 } 80 }
85 }; 81 };
86 82
87 #if !defined(OS_ANDROID)
88 // The GNU C++ library provides identity hash functions for many integral types, 83 // 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 84 // 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 85 // narrower than |long long|. This is probably good enough for what we will
91 // use it for. 86 // use it for.
92 87
93 #define DEFINE_TRIVIAL_HASH(integral_type) \ 88 #define DEFINE_TRIVIAL_HASH(integral_type) \
94 template<> \ 89 template<> \
95 struct hash<integral_type> { \ 90 struct hash<integral_type> { \
96 std::size_t operator()(integral_type value) const { \ 91 std::size_t operator()(integral_type value) const { \
97 return static_cast<std::size_t>(value); \ 92 return static_cast<std::size_t>(value); \
98 } \ 93 } \
99 } 94 }
100 95
101 DEFINE_TRIVIAL_HASH(long long); 96 DEFINE_TRIVIAL_HASH(long long);
102 DEFINE_TRIVIAL_HASH(unsigned long long); 97 DEFINE_TRIVIAL_HASH(unsigned long long);
103 98
104 #undef DEFINE_TRIVIAL_HASH 99 #undef DEFINE_TRIVIAL_HASH
105 #endif // !defined(OS_ANDROID)
106 100
107 // Implement string hash functions so that strings of various flavors can 101 // 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 102 // 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 103 // 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 104 // versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI
111 // is disabled, as it is in our build. 105 // is disabled, as it is in our build.
112 106
113 #define DEFINE_STRING_HASH(string_type) \ 107 #define DEFINE_STRING_HASH(string_type) \
114 template<> \ 108 template<> \
115 struct hash<string_type> { \ 109 struct hash<string_type> { \
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return base::HashPair(value.first, value.second); 313 return base::HashPair(value.first, value.second);
320 } 314 }
321 }; 315 };
322 316
323 } 317 }
324 318
325 #undef DEFINE_PAIR_HASH_FUNCTION_START 319 #undef DEFINE_PAIR_HASH_FUNCTION_START
326 #undef DEFINE_PAIR_HASH_FUNCTION_END 320 #undef DEFINE_PAIR_HASH_FUNCTION_END
327 321
328 #endif // BASE_CONTAINERS_HASH_TABLES_H_ 322 #endif // BASE_CONTAINERS_HASH_TABLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698