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

Side by Side Diff: src/profile-generator.cc

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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/list-inl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 reinterpret_cast<char*>(last_entry) + last_entry->EntrySize())); 1249 reinterpret_cast<char*>(last_entry) + last_entry->EntrySize()));
1250 } else { 1250 } else {
1251 entries_.Add(reinterpret_cast<HeapEntry*>(raw_entries_)); 1251 entries_.Add(reinterpret_cast<HeapEntry*>(raw_entries_));
1252 } 1252 }
1253 ASSERT(reinterpret_cast<char*>(entries_.last()) < 1253 ASSERT(reinterpret_cast<char*>(entries_.last()) <
1254 (raw_entries_ + raw_entries_size_)); 1254 (raw_entries_ + raw_entries_size_));
1255 return entries_.last(); 1255 return entries_.last();
1256 } 1256 }
1257 1257
1258 1258
1259 class FindEntryById {
1260 public:
1261 explicit FindEntryById(SnapshotObjectId id) : id_(id) { }
1262 int operator()(HeapEntry* const* entry) {
1263 if ((*entry)->id() == id_) return 0;
1264 return (*entry)->id() < id_ ? -1 : 1;
1265 }
1266 private:
1267 SnapshotObjectId id_;
1268 };
1269
1270
1259 HeapEntry* HeapSnapshot::GetEntryById(SnapshotObjectId id) { 1271 HeapEntry* HeapSnapshot::GetEntryById(SnapshotObjectId id) {
1260 List<HeapEntry*>* entries_by_id = GetSortedEntriesList(); 1272 List<HeapEntry*>* entries_by_id = GetSortedEntriesList();
1261
1262 // Perform a binary search by id. 1273 // Perform a binary search by id.
1263 int low = 0; 1274 int index = SortedListBSearch(*entries_by_id, FindEntryById(id));
1264 int high = entries_by_id->length() - 1; 1275 if (index == -1)
1265 while (low <= high) { 1276 return NULL;
1266 int mid = 1277 return entries_by_id->at(index);
1267 (static_cast<unsigned int>(low) + static_cast<unsigned int>(high)) >> 1;
1268 SnapshotObjectId mid_id = entries_by_id->at(mid)->id();
1269 if (mid_id > id)
1270 high = mid - 1;
1271 else if (mid_id < id)
1272 low = mid + 1;
1273 else
1274 return entries_by_id->at(mid);
1275 }
1276 return NULL;
1277 } 1278 }
1278 1279
1279 1280
1280 template<class T> 1281 template<class T>
1281 static int SortByIds(const T* entry1_ptr, 1282 static int SortByIds(const T* entry1_ptr,
1282 const T* entry2_ptr) { 1283 const T* entry2_ptr) {
1283 if ((*entry1_ptr)->id() == (*entry2_ptr)->id()) return 0; 1284 if ((*entry1_ptr)->id() == (*entry2_ptr)->id()) return 0;
1284 return (*entry1_ptr)->id() < (*entry2_ptr)->id() ? -1 : 1; 1285 return (*entry1_ptr)->id() < (*entry2_ptr)->id() ? -1 : 1;
1285 } 1286 }
1286 1287
(...skipping 2469 matching lines...) Expand 10 before | Expand all | Expand 10 after
3756 3757
3757 3758
3758 void HeapSnapshotJSONSerializer::SortHashMap( 3759 void HeapSnapshotJSONSerializer::SortHashMap(
3759 HashMap* map, List<HashMap::Entry*>* sorted_entries) { 3760 HashMap* map, List<HashMap::Entry*>* sorted_entries) {
3760 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) 3761 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p))
3761 sorted_entries->Add(p); 3762 sorted_entries->Add(p);
3762 sorted_entries->Sort(SortUsingEntryValue); 3763 sorted_entries->Sort(SortUsingEntryValue);
3763 } 3764 }
3764 3765
3765 } } // namespace v8::internal 3766 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/list-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698