OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project 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 V8_HYDROGEN_UNIQUE_H_ | 5 #ifndef V8_HYDROGEN_UNIQUE_H_ |
6 #define V8_HYDROGEN_UNIQUE_H_ | 6 #define V8_HYDROGEN_UNIQUE_H_ |
7 | 7 |
| 8 #include <ostream> // NOLINT(readability/streams) |
| 9 |
| 10 #include "src/base/functional.h" |
8 #include "src/handles-inl.h" // TODO(everyone): Fix our inl.h crap | 11 #include "src/handles-inl.h" // TODO(everyone): Fix our inl.h crap |
9 #include "src/objects-inl.h" // TODO(everyone): Fix our inl.h crap | 12 #include "src/objects-inl.h" // TODO(everyone): Fix our inl.h crap |
10 #include "src/string-stream.h" | |
11 #include "src/utils.h" | 13 #include "src/utils.h" |
12 #include "src/zone.h" | 14 #include "src/zone.h" |
13 | 15 |
14 namespace v8 { | 16 namespace v8 { |
15 namespace internal { | 17 namespace internal { |
16 | 18 |
17 | 19 |
18 template <typename T> | 20 template <typename T> |
19 class UniqueSet; | 21 class UniqueSet; |
20 | 22 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 DCHECK(IsInitialized() && other.IsInitialized()); | 76 DCHECK(IsInitialized() && other.IsInitialized()); |
75 return raw_address_ == other.raw_address_; | 77 return raw_address_ == other.raw_address_; |
76 } | 78 } |
77 | 79 |
78 template <typename U> | 80 template <typename U> |
79 inline bool operator!=(const Unique<U>& other) const { | 81 inline bool operator!=(const Unique<U>& other) const { |
80 DCHECK(IsInitialized() && other.IsInitialized()); | 82 DCHECK(IsInitialized() && other.IsInitialized()); |
81 return raw_address_ != other.raw_address_; | 83 return raw_address_ != other.raw_address_; |
82 } | 84 } |
83 | 85 |
| 86 friend inline size_t hash_value(Unique<T> const& unique) { |
| 87 DCHECK(unique.IsInitialized()); |
| 88 return base::hash<void*>()(unique.raw_address_); |
| 89 } |
| 90 |
84 inline intptr_t Hashcode() const { | 91 inline intptr_t Hashcode() const { |
85 DCHECK(IsInitialized()); | 92 DCHECK(IsInitialized()); |
86 return reinterpret_cast<intptr_t>(raw_address_); | 93 return reinterpret_cast<intptr_t>(raw_address_); |
87 } | 94 } |
88 | 95 |
89 inline bool IsNull() const { | 96 inline bool IsNull() const { |
90 DCHECK(IsInitialized()); | 97 DCHECK(IsInitialized()); |
91 return raw_address_ == NULL; | 98 return raw_address_ == NULL; |
92 } | 99 } |
93 | 100 |
(...skipping 27 matching lines...) Expand all Loading... |
121 template <class U> | 128 template <class U> |
122 friend class Unique; // For comparing raw_address values. | 129 friend class Unique; // For comparing raw_address values. |
123 | 130 |
124 protected: | 131 protected: |
125 Address raw_address_; | 132 Address raw_address_; |
126 Handle<T> handle_; | 133 Handle<T> handle_; |
127 | 134 |
128 friend class SideEffectsTracker; | 135 friend class SideEffectsTracker; |
129 }; | 136 }; |
130 | 137 |
| 138 template <typename T> |
| 139 inline std::ostream& operator<<(std::ostream& os, Unique<T> uniq) { |
| 140 return os << Brief(*uniq.handle()); |
| 141 } |
| 142 |
131 | 143 |
132 template <typename T> | 144 template <typename T> |
133 class UniqueSet FINAL : public ZoneObject { | 145 class UniqueSet FINAL : public ZoneObject { |
134 public: | 146 public: |
135 // Constructor. A new set will be empty. | 147 // Constructor. A new set will be empty. |
136 UniqueSet() : size_(0), capacity_(0), array_(NULL) { } | 148 UniqueSet() : size_(0), capacity_(0), array_(NULL) { } |
137 | 149 |
138 // Capacity constructor. A new set will be empty. | 150 // Capacity constructor. A new set will be empty. |
139 UniqueSet(int capacity, Zone* zone) | 151 UniqueSet(int capacity, Zone* zone) |
140 : size_(0), capacity_(capacity), | 152 : size_(0), capacity_(capacity), |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 350 } |
339 capacity_ = new_capacity; | 351 capacity_ = new_capacity; |
340 array_ = new_array; | 352 array_ = new_array; |
341 } | 353 } |
342 } | 354 } |
343 }; | 355 }; |
344 | 356 |
345 } } // namespace v8::internal | 357 } } // namespace v8::internal |
346 | 358 |
347 #endif // V8_HYDROGEN_UNIQUE_H_ | 359 #endif // V8_HYDROGEN_UNIQUE_H_ |
OLD | NEW |