Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Unified Diff: src/list-inl.h

Issue 10006032: Use SortedListBSearch instead of custom one in heap profiler (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/list.h ('k') | src/profile-generator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/list-inl.h
===================================================================
--- src/list-inl.h (revision 11245)
+++ src/list-inl.h (working copy)
@@ -207,20 +207,19 @@
}
-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 +230,21 @@
}
+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));
}
« no previous file with comments | « src/list.h ('k') | src/profile-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698