[cleanup] Replace List::BinarySearch with std::lower_bound.
Also-by:ahaas@chromium.org R:ahaas@chromium.org Bug:v8:6325 Change-Id: I5fc7891a2201ac9a889bceec668b23b46e402545 Reviewed-on: https://chromium-review.googlesource.com/490109 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Franziska Hinkelmann <franzih@chromium.org> Cr-Commit-Position: refs/heads/master@{#44981}
This commit is contained in:
parent
a93a769438
commit
f63aaee990
@ -245,41 +245,6 @@ void List<T, P>::StableSort() {
|
||||
ToVector().StableSort();
|
||||
}
|
||||
|
||||
|
||||
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 - low) / 2;
|
||||
T mid_elem = list[mid];
|
||||
|
||||
if (cmp(&mid_elem) > 0) {
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
if (cmp(&mid_elem) < 0) {
|
||||
low = mid + 1;
|
||||
continue;
|
||||
}
|
||||
// Found the element.
|
||||
return mid;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
class ElementCmp {
|
||||
public:
|
||||
explicit ElementCmp(T e) : elem_(e) {}
|
||||
int operator()(const T* other) {
|
||||
return PointerValueCompare(other, &elem_);
|
||||
}
|
||||
private:
|
||||
T elem_;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
|
@ -217,15 +217,6 @@ typedef List<Handle<Map> > MapHandleList;
|
||||
typedef List<Handle<FieldType> > TypeHandleList;
|
||||
typedef List<Handle<Code> > CodeHandleList;
|
||||
|
||||
// Perform binary search for an element in an already sorted
|
||||
// list. Returns the index of the element of -1 if it was not found.
|
||||
// |cmp| is a predicate that takes a pointer to an element of the List
|
||||
// and returns +1 if it is greater, -1 if it is less than the element
|
||||
// being searched.
|
||||
template <typename T, class P>
|
||||
int SortedListBSearch(const List<T>& list, P cmp);
|
||||
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
|
@ -306,11 +306,13 @@ class FindEntryById {
|
||||
|
||||
HeapEntry* HeapSnapshot::GetEntryById(SnapshotObjectId id) {
|
||||
List<HeapEntry*>* entries_by_id = GetSortedEntriesList();
|
||||
// Perform a binary search by id.
|
||||
int index = SortedListBSearch(*entries_by_id, FindEntryById(id));
|
||||
if (index == -1)
|
||||
return NULL;
|
||||
return entries_by_id->at(index);
|
||||
|
||||
auto it = std::lower_bound(
|
||||
entries_by_id->begin(), entries_by_id->end(), id,
|
||||
[](HeapEntry* first, SnapshotObjectId val) { return first->id() < val; });
|
||||
|
||||
if (it == entries_by_id->end() || (*it)->id() != id) return NULL;
|
||||
return *it;
|
||||
}
|
||||
|
||||
|
||||
|
@ -161,13 +161,6 @@ int Compare(const T& a, const T& b) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
int PointerValueCompare(const T* a, const T* b) {
|
||||
return Compare<T>(*a, *b);
|
||||
}
|
||||
|
||||
|
||||
// Compare function to compare the object pointer value of two
|
||||
// handlified objects. The handles are passed as pointers to the
|
||||
// handles.
|
||||
|
Loading…
Reference in New Issue
Block a user