Chromium Code Reviews| Index: src/list-inl.h |
| =================================================================== |
| --- src/list-inl.h (revision 6353) |
| +++ src/list-inl.h (working copy) |
| @@ -201,6 +201,54 @@ |
| } |
| +template<typename T, class P> |
| +void SearchableList<T, P>::Add(const T& element) { |
| + is_sorted_ = false; |
| + List<T, P>::Add(element); |
| +} |
| + |
| + |
| +template<typename T, class P> |
| +void SearchableList<T, P>::AddAll(const List<T, P>& other) { |
| + is_sorted_ = false; |
| + List<T, P>::AddAll(other); |
| +} |
| + |
| + |
| +template<typename T, class P> |
| +Vector<T> SearchableList<T, P>::AddBlock(T value, int count) { |
| + is_sorted_ = false; |
| + return List<T, P>::AddBlock(value, count); |
| +} |
| + |
| + |
| +template<typename T, class P> |
| +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
|
| + if (is_sorted_) { |
| + return ContainsSorted(elm); |
| + } |
| + return List<T, P>::Contains(elm); |
| +} |
| + |
| + |
| +template<typename T, class P> |
| +void SearchableList<T, P>::Sort() { |
| + if (!is_sorted_) { |
| + List<T, P>::Sort(comparator_); |
| + is_sorted_ = true; |
| + } |
| +} |
| + |
| + |
| +template<typename T, class P> |
| +bool SearchableList<T, P>::ContainsSorted(const T& elm) { |
| + typedef int (*RawComparer)(const void*, const void*); |
| + 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.
|
| + sizeof(T), |
| + reinterpret_cast<RawComparer>(comparator_))); |
| +} |
| + |
| + |
| } } // namespace v8::internal |
| #endif // V8_LIST_INL_H_ |