| Index: src/list-inl.h
|
| ===================================================================
|
| --- src/list-inl.h (revision 6372)
|
| +++ src/list-inl.h (working copy)
|
| @@ -201,6 +201,65 @@
|
| }
|
|
|
|
|
| +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) {
|
| + if (is_sorted_) {
|
| + return ContainsSorted(elm);
|
| + }
|
| + return List<T, P>::Contains(elm);
|
| +}
|
| +
|
| +
|
| +template<typename T, class P>
|
| +bool SearchableList<T, P>::Contains(const T& elm, bool ensure_sorted) {
|
| + if (ensure_sorted) {
|
| + Sort(); // Will only sort if not already sorted.
|
| + }
|
| + 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(),
|
| + sizeof(T),
|
| + reinterpret_cast<RawComparer>(comparator_)));
|
| +}
|
| +
|
| +
|
| } } // namespace v8::internal
|
|
|
| #endif // V8_LIST_INL_H_
|
|
|