Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 | 194 |
| 195 template<typename T, class P> | 195 template<typename T, class P> |
| 196 void List<T, P>::Initialize(int capacity) { | 196 void List<T, P>::Initialize(int capacity) { |
| 197 ASSERT(capacity >= 0); | 197 ASSERT(capacity >= 0); |
| 198 data_ = (capacity > 0) ? NewData(capacity) : NULL; | 198 data_ = (capacity > 0) ? NewData(capacity) : NULL; |
| 199 capacity_ = capacity; | 199 capacity_ = capacity; |
| 200 length_ = 0; | 200 length_ = 0; |
| 201 } | 201 } |
| 202 | 202 |
| 203 | 203 |
| 204 template<typename T, class P> | |
| 205 void SearchableList<T, P>::Add(const T& element) { | |
| 206 is_sorted_ = false; | |
| 207 List<T, P>::Add(element); | |
| 208 } | |
| 209 | |
| 210 | |
| 211 template<typename T, class P> | |
| 212 void SearchableList<T, P>::AddAll(const List<T, P>& other) { | |
| 213 is_sorted_ = false; | |
| 214 List<T, P>::AddAll(other); | |
| 215 } | |
| 216 | |
| 217 | |
| 218 template<typename T, class P> | |
| 219 Vector<T> SearchableList<T, P>::AddBlock(T value, int count) { | |
| 220 is_sorted_ = false; | |
| 221 return List<T, P>::AddBlock(value, count); | |
| 222 } | |
| 223 | |
| 224 | |
| 225 template<typename T, class P> | |
| 226 bool SearchableList<T, P>::Contains(const T& elm) { | |
|
Søren Thygesen Gjesse
2011/01/18 07:44:40
Have you considered just sorting here if the list
marklam
2011/01/18 22:33:16
Done. I added a second Contains() which takes a b
| |
| 227 if (is_sorted_) { | |
| 228 return ContainsSorted(elm); | |
| 229 } | |
| 230 return List<T, P>::Contains(elm); | |
| 231 } | |
| 232 | |
| 233 | |
| 234 template<typename T, class P> | |
| 235 void SearchableList<T, P>::Sort() { | |
| 236 if (!is_sorted_) { | |
| 237 List<T, P>::Sort(comparator_); | |
| 238 is_sorted_ = true; | |
| 239 } | |
| 240 } | |
| 241 | |
| 242 | |
| 243 template<typename T, class P> | |
| 244 bool SearchableList<T, P>::ContainsSorted(const T& elm) { | |
| 245 typedef int (*RawComparer)(const void*, const void*); | |
| 246 return (NULL != bsearch(&elm, List<T, P>::data(), List<T, P>::length(), | |
|
Søren Thygesen Gjesse
2011/01/18 07:44:40
One argument per line when splitting.
marklam
2011/01/18 22:33:16
Done.
| |
| 247 sizeof(T), | |
| 248 reinterpret_cast<RawComparer>(comparator_))); | |
| 249 } | |
| 250 | |
| 251 | |
| 204 } } // namespace v8::internal | 252 } } // namespace v8::internal |
| 205 | 253 |
| 206 #endif // V8_LIST_INL_H_ | 254 #endif // V8_LIST_INL_H_ |
| OLD | NEW |