OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 list->Add(single_value()); | 62 list->Add(single_value()); |
63 } | 63 } |
64 ASSERT(IsAligned(reinterpret_cast<intptr_t>(list), kPointerAlignment)); | 64 ASSERT(IsAligned(reinterpret_cast<intptr_t>(list), kPointerAlignment)); |
65 data_ = reinterpret_cast<intptr_t>(list) | kListTag; | 65 data_ = reinterpret_cast<intptr_t>(list) | kListTag; |
66 } | 66 } |
67 | 67 |
68 void Clear() { | 68 void Clear() { |
69 data_ = kEmptyTag; | 69 data_ = kEmptyTag; |
70 } | 70 } |
71 | 71 |
| 72 void Sort() { |
| 73 if ((data_ & kTagMask) == kListTag) { |
| 74 list()->Sort(compare_value); |
| 75 } |
| 76 } |
| 77 |
72 bool is_empty() const { return length() == 0; } | 78 bool is_empty() const { return length() == 0; } |
73 | 79 |
74 int length() const { | 80 int length() const { |
75 if ((data_ & kTagMask) == kEmptyTag) return 0; | 81 if ((data_ & kTagMask) == kEmptyTag) return 0; |
76 if ((data_ & kTagMask) == kSingletonTag) return 1; | 82 if ((data_ & kTagMask) == kSingletonTag) return 1; |
77 return list()->length(); | 83 return list()->length(); |
78 } | 84 } |
79 | 85 |
80 void Add(T* pointer) { | 86 void Add(T* pointer) { |
81 ASSERT(IsAligned(reinterpret_cast<intptr_t>(pointer), kPointerAlignment)); | 87 ASSERT(IsAligned(reinterpret_cast<intptr_t>(pointer), kPointerAlignment)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 return (single_value() == pointer) ? 1 : 0; | 158 return (single_value() == pointer) ? 1 : 0; |
153 } | 159 } |
154 return 0; | 160 return 0; |
155 } | 161 } |
156 return list()->CountOccurrences(pointer, start, end); | 162 return list()->CountOccurrences(pointer, start, end); |
157 } | 163 } |
158 | 164 |
159 private: | 165 private: |
160 typedef ZoneList<T*> PointerList; | 166 typedef ZoneList<T*> PointerList; |
161 | 167 |
| 168 static int compare_value(T* const* a, T* const* b) { |
| 169 return Compare<T>(**a, **b); |
| 170 } |
| 171 |
162 static const intptr_t kEmptyTag = 1; | 172 static const intptr_t kEmptyTag = 1; |
163 static const intptr_t kSingletonTag = 0; | 173 static const intptr_t kSingletonTag = 0; |
164 static const intptr_t kListTag = 2; | 174 static const intptr_t kListTag = 2; |
165 static const intptr_t kTagMask = 3; | 175 static const intptr_t kTagMask = 3; |
166 static const intptr_t kValueMask = ~kTagMask; | 176 static const intptr_t kValueMask = ~kTagMask; |
167 | 177 |
168 STATIC_ASSERT(kTagMask + 1 <= kPointerAlignment); | 178 STATIC_ASSERT(kTagMask + 1 <= kPointerAlignment); |
169 | 179 |
170 T* single_value() const { | 180 T* single_value() const { |
171 ASSERT((data_ & kTagMask) == kSingletonTag); | 181 ASSERT((data_ & kTagMask) == kSingletonTag); |
172 STATIC_ASSERT(kSingletonTag == 0); | 182 STATIC_ASSERT(kSingletonTag == 0); |
173 return reinterpret_cast<T*>(data_); | 183 return reinterpret_cast<T*>(data_); |
174 } | 184 } |
175 | 185 |
176 PointerList* list() const { | 186 PointerList* list() const { |
177 ASSERT((data_ & kTagMask) == kListTag); | 187 ASSERT((data_ & kTagMask) == kListTag); |
178 return reinterpret_cast<PointerList*>(data_ & kValueMask); | 188 return reinterpret_cast<PointerList*>(data_ & kValueMask); |
179 } | 189 } |
180 | 190 |
181 intptr_t data_; | 191 intptr_t data_; |
182 | 192 |
183 DISALLOW_COPY_AND_ASSIGN(SmallPointerList); | 193 DISALLOW_COPY_AND_ASSIGN(SmallPointerList); |
184 }; | 194 }; |
185 | 195 |
186 } } // namespace v8::internal | 196 } } // namespace v8::internal |
187 | 197 |
188 #endif // V8_SMALL_POINTER_LIST_H_ | 198 #endif // V8_SMALL_POINTER_LIST_H_ |
OLD | NEW |