Index: src/profile-generator.cc |
=================================================================== |
--- src/profile-generator.cc (revision 11246) |
+++ src/profile-generator.cc (working copy) |
@@ -1256,24 +1256,25 @@ |
} |
+class FindEntryById { |
+ public: |
+ explicit FindEntryById(SnapshotObjectId id) : id_(id) { } |
+ int operator()(HeapEntry* const* entry) { |
+ if ((*entry)->id() == id_) return 0; |
+ return (*entry)->id() < id_ ? -1 : 1; |
+ } |
+ private: |
+ SnapshotObjectId id_; |
+}; |
+ |
+ |
HeapEntry* HeapSnapshot::GetEntryById(SnapshotObjectId id) { |
List<HeapEntry*>* entries_by_id = GetSortedEntriesList(); |
- |
// Perform a binary search by id. |
- int low = 0; |
- int high = entries_by_id->length() - 1; |
- while (low <= high) { |
- int mid = |
- (static_cast<unsigned int>(low) + static_cast<unsigned int>(high)) >> 1; |
- SnapshotObjectId mid_id = entries_by_id->at(mid)->id(); |
- if (mid_id > id) |
- high = mid - 1; |
- else if (mid_id < id) |
- low = mid + 1; |
- else |
- return entries_by_id->at(mid); |
- } |
- return NULL; |
+ int index = SortedListBSearch(*entries_by_id, FindEntryById(id)); |
+ if (index == -1) |
+ return NULL; |
+ return entries_by_id->at(index); |
} |