Chromium Code Reviews| Index: base/trace_event/heap_profiler_allocation_context.cc |
| diff --git a/base/trace_event/heap_profiler_allocation_context.cc b/base/trace_event/heap_profiler_allocation_context.cc |
| index 038c083f0fa83241f9fef46c0ed239572d282d62..790c966b91c2859a7eb21d9700ed257b7634ac00 100644 |
| --- a/base/trace_event/heap_profiler_allocation_context.cc |
| +++ b/base/trace_event/heap_profiler_allocation_context.cc |
| @@ -12,6 +12,18 @@ |
| namespace base { |
| namespace trace_event { |
| +bool operator < (const StackFrame& lhs, const StackFrame& rhs) { |
| + return lhs.value < rhs.value; |
| +} |
| + |
| +bool operator == (const StackFrame& lhs, const StackFrame& rhs) { |
| + return lhs.value == rhs.value; |
| +} |
| + |
| +bool operator != (const StackFrame& lhs, const StackFrame& rhs) { |
| + return lhs.value != rhs.value; |
|
Primiano Tucci (use gerrit)
2016/04/19 19:45:06
small thing. I'd probably just implement this as !
Dmitry Skiba
2016/04/19 22:14:14
Done.
|
| +} |
| + |
| // Constructor that does not initialize members. |
| AllocationContext::AllocationContext() {} |
| @@ -19,18 +31,15 @@ AllocationContext::AllocationContext() {} |
| AllocationContext AllocationContext::Empty() { |
| AllocationContext ctx; |
|
Primiano Tucci (use gerrit)
2016/04/19 19:45:06
At this point can we remove this and make this int
Dmitry Skiba
2016/04/19 22:14:14
Done.
|
| - for (size_t i = 0; i < arraysize(ctx.backtrace.frames); i++) |
| - ctx.backtrace.frames[i] = nullptr; |
| - |
| + ctx.backtrace.frame_count = 0; |
| ctx.type_name = nullptr; |
| return ctx; |
| } |
| bool operator==(const Backtrace& lhs, const Backtrace& rhs) { |
| - // Pointer equality of the stack frames is assumed, so instead of doing a deep |
| - // string comparison on all of the frames, a |memcmp| suffices. |
| - return std::memcmp(lhs.frames, rhs.frames, sizeof(lhs.frames)) == 0; |
| + if (lhs.frame_count != rhs.frame_count) return false; |
| + return std::equal(lhs.frames, lhs.frames + lhs.frame_count, rhs.frames); |
| } |
| bool operator==(const AllocationContext& lhs, const AllocationContext& rhs) { |
| @@ -43,10 +52,19 @@ bool operator==(const AllocationContext& lhs, const AllocationContext& rhs) { |
| namespace BASE_HASH_NAMESPACE { |
| using base::trace_event::AllocationContext; |
| using base::trace_event::Backtrace; |
| +using base::trace_event::StackFrame; |
| + |
| +size_t hash<StackFrame>::operator()(const StackFrame& frame) const { |
| + return hash<const void*>()(frame.value); |
| +} |
| size_t hash<Backtrace>::operator()(const Backtrace& backtrace) const { |
| - return base::SuperFastHash(reinterpret_cast<const char*>(backtrace.frames), |
| - sizeof(backtrace.frames)); |
| + const void* values[Backtrace::kMaxFrameCount]; |
| + for (size_t i = 0; i != backtrace.frame_count; ++i) { |
| + values[i] = backtrace.frames[i].value; |
| + } |
| + return base::SuperFastHash(reinterpret_cast<const char*>(values), |
| + backtrace.frame_count * sizeof(*values)); |
| } |
| size_t hash<AllocationContext>::operator()(const AllocationContext& ctx) const { |