| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/trace_event/heap_profiler_allocation_context.h" | 5 #include "base/trace_event/heap_profiler_allocation_context.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "base/hash.h" | 9 #include "base/hash.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 namespace trace_event { | 13 namespace trace_event { |
| 14 | 14 |
| 15 // Constructor that does not initialize members. | 15 // Constructor that does not initialize members. |
| 16 AllocationContext::AllocationContext() {} | 16 AllocationContext::AllocationContext() {} |
| 17 | 17 |
| 18 // static | 18 // static |
| 19 AllocationContext AllocationContext::Empty() { | 19 AllocationContext AllocationContext::Empty() { |
| 20 AllocationContext ctx; | 20 AllocationContext ctx; |
| 21 | 21 |
| 22 ctx.backtrace.frame_type = STACK_FRAME_TYPE_SYMBOL; |
| 22 for (size_t i = 0; i < arraysize(ctx.backtrace.frames); i++) | 23 for (size_t i = 0; i < arraysize(ctx.backtrace.frames); i++) |
| 23 ctx.backtrace.frames[i] = nullptr; | 24 ctx.backtrace.frames[i] = nullptr; |
| 24 | 25 |
| 25 ctx.type_name = nullptr; | 26 ctx.type_name = nullptr; |
| 26 | 27 |
| 27 return ctx; | 28 return ctx; |
| 28 } | 29 } |
| 29 | 30 |
| 30 bool operator==(const Backtrace& lhs, const Backtrace& rhs) { | 31 bool operator==(const Backtrace& lhs, const Backtrace& rhs) { |
| 31 // Pointer equality of the stack frames is assumed, so instead of doing a deep | 32 // Pointer equality of the stack frames is assumed, so instead of doing a deep |
| (...skipping 26 matching lines...) Expand all Loading... |
| 58 // the magic number is coprime to 2^64. | 59 // the magic number is coprime to 2^64. |
| 59 size_t type_hash = reinterpret_cast<size_t>(ctx.type_name) * 2654435761; | 60 size_t type_hash = reinterpret_cast<size_t>(ctx.type_name) * 2654435761; |
| 60 | 61 |
| 61 // Multiply one side to break the commutativity of +. Multiplication with a | 62 // Multiply one side to break the commutativity of +. Multiplication with a |
| 62 // number coprime to |numeric_limits<size_t>::max() + 1| is bijective so | 63 // number coprime to |numeric_limits<size_t>::max() + 1| is bijective so |
| 63 // randomness is preserved. | 64 // randomness is preserved. |
| 64 return (backtrace_hash * 3) + type_hash; | 65 return (backtrace_hash * 3) + type_hash; |
| 65 } | 66 } |
| 66 | 67 |
| 67 } // BASE_HASH_NAMESPACE | 68 } // BASE_HASH_NAMESPACE |
| OLD | NEW |