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

Unified Diff: base/trace_event/heap_profiler_allocation_register.cc

Issue 1574493002: [Tracing] Add lookup support to AllocationRegister (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
Index: base/trace_event/heap_profiler_allocation_register.cc
diff --git a/base/trace_event/heap_profiler_allocation_register.cc b/base/trace_event/heap_profiler_allocation_register.cc
index 825a0d0b9ad1d4e5d247167858701758e45f214a..9a846c5613c2ad4924c943a0cfb27e98d2a414fe 100644
--- a/base/trace_event/heap_profiler_allocation_register.cc
+++ b/base/trace_event/heap_profiler_allocation_register.cc
@@ -43,7 +43,11 @@ void AllocationRegister::Insert(void* address,
if (*idx_ptr == 0) {
*idx_ptr = GetFreeCell();
- cells_[*idx_ptr].allocation.address = address;
+ // The address stored in a cell is const as long as it is exposed (via the
+ // iterators or |Get|), but because cells are re-used, a const cast is
+ // required to set it on insert and remove.
+ void* const& allocation_address = cells_[*idx_ptr].allocation.address;
+ const_cast<void*&>(allocation_address) = address;
cells_[*idx_ptr].next = 0;
}
@@ -71,7 +75,14 @@ void AllocationRegister::Remove(void* address) {
free_list_ = freed_idx;
// Reset the address, so that on iteration the free cell is ignored.
- freed_cell->allocation.address = nullptr;
+ const_cast<void*&>(freed_cell->allocation.address) = nullptr;
+}
+
+AllocationRegister::Allocation* AllocationRegister::Get(void* address) {
+ CellIndex* idx_ptr = Lookup(address);
+
+ // If the index is 0, the address is not present in the table.
+ return *idx_ptr == 0 ? nullptr : &cells_[*idx_ptr].allocation;
}
AllocationRegister::ConstIterator AllocationRegister::begin() const {
« no previous file with comments | « base/trace_event/heap_profiler_allocation_register.h ('k') | base/trace_event/heap_profiler_allocation_register_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698