| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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_ |
| OLD | NEW |