diff options
author | isaacs <i@izs.me> | 2012-05-15 19:53:16 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-05-16 14:22:33 -0700 |
commit | 3f3f958c14cf4e963a73d6f037ac381c77fe78bb (patch) | |
tree | 391e35b59e76d038534fbd375f1bbe0dc55076cf /deps/v8/src/list-inl.h | |
parent | 4099d1eebae4e78864a6879c0b9e08f31d48d8cb (diff) | |
download | node-new-3f3f958c14cf4e963a73d6f037ac381c77fe78bb.tar.gz |
Upgrade V8 to 3.11.1
Diffstat (limited to 'deps/v8/src/list-inl.h')
-rw-r--r-- | deps/v8/src/list-inl.h | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/deps/v8/src/list-inl.h b/deps/v8/src/list-inl.h index 7c2c83f0f7..6cf3badc62 100644 --- a/deps/v8/src/list-inl.h +++ b/deps/v8/src/list-inl.h @@ -137,6 +137,14 @@ bool List<T, P>::RemoveElement(const T& elm) { template<typename T, class P> +void List<T, P>::Allocate(int length) { + DeleteData(data_); + Initialize(length); + length_ = length; +} + + +template<typename T, class P> void List<T, P>::Clear() { DeleteData(data_); Initialize(0); @@ -207,20 +215,19 @@ void List<T, P>::Initialize(int capacity) { } -template <typename T> -int SortedListBSearch( - const List<T>& list, T elem, int (*cmp)(const T* x, const T* y)) { +template <typename T, typename P> +int SortedListBSearch(const List<T>& list, P cmp) { int low = 0; int high = list.length() - 1; while (low <= high) { int mid = (low + high) / 2; T mid_elem = list[mid]; - if (cmp(&mid_elem, &elem) > 0) { + if (cmp(&mid_elem) > 0) { high = mid - 1; continue; } - if (cmp(&mid_elem, &elem) < 0) { + if (cmp(&mid_elem) < 0) { low = mid + 1; continue; } @@ -231,9 +238,21 @@ int SortedListBSearch( } +template<typename T> +class ElementCmp { + public: + explicit ElementCmp(T e) : elem_(e) {} + int operator()(const T* other) { + return PointerValueCompare(other, &elem_); + } + private: + T elem_; +}; + + template <typename T> int SortedListBSearch(const List<T>& list, T elem) { - return SortedListBSearch<T>(list, elem, PointerValueCompare<T>); + return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); } |