aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/list-inl.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/list-inl.h')
-rw-r--r--deps/v8/src/list-inl.h31
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));
}