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

Side by Side Diff: tools/gn/unique_vector.h

Issue 612323010: Align base::hash_map with C++11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Try a different tack for C++ insanity Created 6 years, 2 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 TOOLS_GN_UNIQUE_VECTOR_H_ 5 #ifndef TOOLS_GN_UNIQUE_VECTOR_H_
6 #define TOOLS_GN_UNIQUE_VECTOR_H_ 6 #define TOOLS_GN_UNIQUE_VECTOR_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 index_(i), 56 index_(i),
57 hash_val_(hash_value) { 57 hash_val_(hash_value) {
58 } 58 }
59 59
60 const T& value() const { return value_ ? *value_ : (*vect_)[index_]; } 60 const T& value() const { return value_ ? *value_ : (*vect_)[index_]; }
61 size_t hash_val() const { return hash_val_; } 61 size_t hash_val() const { return hash_val_; }
62 size_t index() const { return index_; } 62 size_t index() const { return index_; }
63 63
64 private: 64 private:
65 void FillHashValue() { 65 void FillHashValue() {
66 #if defined(COMPILER_GCC)
67 BASE_HASH_NAMESPACE::hash<T> h; 66 BASE_HASH_NAMESPACE::hash<T> h;
68 hash_val_ = h(value()); 67 hash_val_ = h(value());
69 #elif defined(COMPILER_MSVC)
70 hash_val_ = BASE_HASH_NAMESPACE::hash_value(value());
71 #else
72 #error write me
73 #endif // COMPILER...
74 } 68 }
75 69
76 // When non-null, points to the object. 70 // When non-null, points to the object.
77 const T* value_; 71 const T* value_;
78 72
79 // When value is null these are used. 73 // When value is null these are used.
80 const std::vector<T>* vect_; 74 const std::vector<T>* vect_;
81 size_t index_; 75 size_t index_;
82 76
83 size_t hash_val_; 77 size_t hash_val_;
84 }; 78 };
85 79
86 template<typename T> inline bool operator==(const UniquifyRef<T>& a, 80 template<typename T> inline bool operator==(const UniquifyRef<T>& a,
87 const UniquifyRef<T>& b) { 81 const UniquifyRef<T>& b) {
88 return a.value() == b.value(); 82 return a.value() == b.value();
89 } 83 }
90 84
91 template<typename T> inline bool operator<(const UniquifyRef<T>& a, 85 template<typename T> inline bool operator<(const UniquifyRef<T>& a,
92 const UniquifyRef<T>& b) { 86 const UniquifyRef<T>& b) {
93 return a.value() < b.value(); 87 return a.value() < b.value();
94 } 88 }
95 89
96 } // namespace internal 90 } // namespace internal
97 91
98 namespace BASE_HASH_NAMESPACE { 92 namespace BASE_HASH_NAMESPACE {
99 93
100 #if defined(COMPILER_GCC)
101 template<typename T> struct hash< internal::UniquifyRef<T> > { 94 template<typename T> struct hash< internal::UniquifyRef<T> > {
102 std::size_t operator()(const internal::UniquifyRef<T>& v) const { 95 std::size_t operator()(const internal::UniquifyRef<T>& v) const {
103 return v.hash_val(); 96 return v.hash_val();
104 } 97 }
105 }; 98 };
106 #elif defined(COMPILER_MSVC)
107 template<typename T>
108 inline size_t hash_value(const internal::UniquifyRef<T>& v) {
109 return v.hash_val();
110 }
111 #endif // COMPILER...
112 99
113 } // namespace BASE_HASH_NAMESPACE 100 } // namespace BASE_HASH_NAMESPACE
114 101
115 // An ordered set optimized for GN's usage. Such sets are used to store lists 102 // An ordered set optimized for GN's usage. Such sets are used to store lists
116 // of configs and libraries, and are appended to but not randomly inserted 103 // of configs and libraries, and are appended to but not randomly inserted
117 // into. 104 // into.
118 template<typename T> 105 template<typename T>
119 class UniqueVector { 106 class UniqueVector {
120 public: 107 public:
121 typedef std::vector<T> Vector; 108 typedef std::vector<T> Vector;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 167
181 private: 168 private:
182 typedef internal::UniquifyRef<T> Ref; 169 typedef internal::UniquifyRef<T> Ref;
183 typedef base::hash_set<Ref> HashSet; 170 typedef base::hash_set<Ref> HashSet;
184 171
185 HashSet set_; 172 HashSet set_;
186 Vector vector_; 173 Vector vector_;
187 }; 174 };
188 175
189 #endif // TOOLS_GN_UNIQUE_VECTOR_H_ 176 #endif // TOOLS_GN_UNIQUE_VECTOR_H_
OLDNEW
« content/renderer/pepper/v8_var_converter.cc ('K') | « tools/gn/target.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698