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

Side by Side Diff: mojo/public/cpp/bindings/struct_ptr.h

Issue 2715153004: Mojo: Support enums as map keys in WTF (Closed)
Patch Set: Address review comments Created 3 years, 9 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
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
7 7
8 #include <functional> 8 #include <functional>
9 #include <memory> 9 #include <memory>
10 #include <new> 10 #include <new>
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 const InlinedStructPtr<T>& rhs) { 221 const InlinedStructPtr<T>& rhs) {
222 return !(lhs == rhs); 222 return !(lhs == rhs);
223 } 223 }
224 224
225 namespace internal { 225 namespace internal {
226 226
227 template <typename Struct> 227 template <typename Struct>
228 class StructPtrWTFHelper { 228 class StructPtrWTFHelper {
229 public: 229 public:
230 static bool IsHashTableDeletedValue(const StructPtr<Struct>& value) { 230 static bool IsHashTableDeletedValue(const StructPtr<Struct>& value) {
231 return value.ptr_ == reinterpret_cast<Struct*>(1u); 231 return value.ptr_.get() == reinterpret_cast<Struct*>(1u);
232 } 232 }
233 233
234 static void ConstructDeletedValue(mojo::StructPtr<Struct>& slot) { 234 static void ConstructDeletedValue(mojo::StructPtr<Struct>& slot) {
235 // |slot| refers to a previous, real value that got deleted and had its 235 // |slot| refers to a previous, real value that got deleted and had its
236 // destructor run, so this is the first time the "deleted value" has its 236 // destructor run, so this is the first time the "deleted value" has its
237 // constructor called. 237 // constructor called.
238 // 238 //
239 // Dirty trick: implant an invalid pointer in |ptr_|. Destructor isn't 239 // Dirty trick: implant an invalid pointer in |ptr_|. Destructor isn't
240 // called for deleted buckets, so this is okay. 240 // called for deleted buckets, so this is okay.
241 new (&slot) StructPtr<Struct>(); 241 new (&slot) StructPtr<Struct>();
242 slot.ptr_ = reinterpret_cast<Struct*>(1u); 242 slot.ptr_.reset(reinterpret_cast<Struct*>(1u));
243 } 243 }
244 }; 244 };
245 245
246 template <typename Struct> 246 template <typename Struct>
247 class InlinedStructPtrWTFHelper { 247 class InlinedStructPtrWTFHelper {
248 public: 248 public:
249 static bool IsHashTableDeletedValue(const InlinedStructPtr<Struct>& value) { 249 static bool IsHashTableDeletedValue(const InlinedStructPtr<Struct>& value) {
250 return value.state_ == InlinedStructPtr<Struct>::DELETED; 250 return value.state_ == InlinedStructPtr<Struct>::DELETED;
251 } 251 }
252 252
(...skipping 21 matching lines...) Expand all
274 template <typename T> 274 template <typename T>
275 struct hash<mojo::InlinedStructPtr<T>> { 275 struct hash<mojo::InlinedStructPtr<T>> {
276 size_t operator()(const mojo::InlinedStructPtr<T>& value) const { 276 size_t operator()(const mojo::InlinedStructPtr<T>& value) const {
277 return value.Hash(mojo::internal::kHashSeed); 277 return value.Hash(mojo::internal::kHashSeed);
278 } 278 }
279 }; 279 };
280 280
281 } // namespace std 281 } // namespace std
282 282
283 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_ 283 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698