| 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" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 const char* type_name) | 41 const char* type_name) |
| 42 : backtrace(backtrace), type_name(type_name) {} | 42 : backtrace(backtrace), type_name(type_name) {} |
| 43 | 43 |
| 44 bool operator==(const AllocationContext& lhs, const AllocationContext& rhs) { | 44 bool operator==(const AllocationContext& lhs, const AllocationContext& rhs) { |
| 45 return (lhs.backtrace == rhs.backtrace) && (lhs.type_name == rhs.type_name); | 45 return (lhs.backtrace == rhs.backtrace) && (lhs.type_name == rhs.type_name); |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool operator!=(const AllocationContext& lhs, const AllocationContext& rhs) { | 48 bool operator!=(const AllocationContext& lhs, const AllocationContext& rhs) { |
| 49 return !(lhs == rhs); | 49 return !(lhs == rhs); |
| 50 } | 50 } |
| 51 |
| 51 } // namespace trace_event | 52 } // namespace trace_event |
| 52 } // namespace base | 53 } // namespace base |
| 53 | 54 |
| 54 namespace BASE_HASH_NAMESPACE { | 55 namespace std { |
| 56 |
| 55 using base::trace_event::AllocationContext; | 57 using base::trace_event::AllocationContext; |
| 56 using base::trace_event::Backtrace; | 58 using base::trace_event::Backtrace; |
| 57 using base::trace_event::StackFrame; | 59 using base::trace_event::StackFrame; |
| 58 | 60 |
| 59 size_t hash<StackFrame>::operator()(const StackFrame& frame) const { | 61 size_t hash<StackFrame>::operator()(const StackFrame& frame) const { |
| 60 return hash<const void*>()(frame.value); | 62 return hash<const void*>()(frame.value); |
| 61 } | 63 } |
| 62 | 64 |
| 63 size_t hash<Backtrace>::operator()(const Backtrace& backtrace) const { | 65 size_t hash<Backtrace>::operator()(const Backtrace& backtrace) const { |
| 64 const void* values[Backtrace::kMaxFrameCount]; | 66 const void* values[Backtrace::kMaxFrameCount]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 78 // will still redistribute keys bijectively on 64-bit architectures because | 80 // will still redistribute keys bijectively on 64-bit architectures because |
| 79 // the magic number is coprime to 2^64. | 81 // the magic number is coprime to 2^64. |
| 80 size_t type_hash = reinterpret_cast<size_t>(ctx.type_name) * 2654435761; | 82 size_t type_hash = reinterpret_cast<size_t>(ctx.type_name) * 2654435761; |
| 81 | 83 |
| 82 // Multiply one side to break the commutativity of +. Multiplication with a | 84 // Multiply one side to break the commutativity of +. Multiplication with a |
| 83 // number coprime to |numeric_limits<size_t>::max() + 1| is bijective so | 85 // number coprime to |numeric_limits<size_t>::max() + 1| is bijective so |
| 84 // randomness is preserved. | 86 // randomness is preserved. |
| 85 return (backtrace_hash * 3) + type_hash; | 87 return (backtrace_hash * 3) + type_hash; |
| 86 } | 88 } |
| 87 | 89 |
| 88 } // BASE_HASH_NAMESPACE | 90 } // namespace std |
| OLD | NEW |