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 13 matching lines...) Expand all Loading... |
24 return !(lhs.value == rhs.value); | 24 return !(lhs.value == rhs.value); |
25 } | 25 } |
26 | 26 |
27 Backtrace::Backtrace(): frame_count(0) {} | 27 Backtrace::Backtrace(): frame_count(0) {} |
28 | 28 |
29 bool operator==(const Backtrace& lhs, const Backtrace& rhs) { | 29 bool operator==(const Backtrace& lhs, const Backtrace& rhs) { |
30 if (lhs.frame_count != rhs.frame_count) return false; | 30 if (lhs.frame_count != rhs.frame_count) return false; |
31 return std::equal(lhs.frames, lhs.frames + lhs.frame_count, rhs.frames); | 31 return std::equal(lhs.frames, lhs.frames + lhs.frame_count, rhs.frames); |
32 } | 32 } |
33 | 33 |
| 34 bool operator!=(const Backtrace& lhs, const Backtrace& rhs) { |
| 35 return !(lhs == rhs); |
| 36 } |
| 37 |
34 AllocationContext::AllocationContext(): type_name(nullptr) {} | 38 AllocationContext::AllocationContext(): type_name(nullptr) {} |
35 | 39 |
| 40 AllocationContext::AllocationContext(const Backtrace& backtrace, |
| 41 const char* type_name) |
| 42 : backtrace(backtrace), type_name(type_name) {} |
| 43 |
36 bool operator==(const AllocationContext& lhs, const AllocationContext& rhs) { | 44 bool operator==(const AllocationContext& lhs, const AllocationContext& rhs) { |
37 return (lhs.backtrace == rhs.backtrace) && (lhs.type_name == rhs.type_name); | 45 return (lhs.backtrace == rhs.backtrace) && (lhs.type_name == rhs.type_name); |
38 } | 46 } |
39 | 47 |
| 48 bool operator!=(const AllocationContext& lhs, const AllocationContext& rhs) { |
| 49 return !(lhs == rhs); |
| 50 } |
40 } // namespace trace_event | 51 } // namespace trace_event |
41 } // namespace base | 52 } // namespace base |
42 | 53 |
43 namespace BASE_HASH_NAMESPACE { | 54 namespace BASE_HASH_NAMESPACE { |
44 using base::trace_event::AllocationContext; | 55 using base::trace_event::AllocationContext; |
45 using base::trace_event::Backtrace; | 56 using base::trace_event::Backtrace; |
46 using base::trace_event::StackFrame; | 57 using base::trace_event::StackFrame; |
47 | 58 |
48 size_t hash<StackFrame>::operator()(const StackFrame& frame) const { | 59 size_t hash<StackFrame>::operator()(const StackFrame& frame) const { |
49 return hash<const void*>()(frame.value); | 60 return hash<const void*>()(frame.value); |
(...skipping 18 matching lines...) Expand all Loading... |
68 // the magic number is coprime to 2^64. | 79 // the magic number is coprime to 2^64. |
69 size_t type_hash = reinterpret_cast<size_t>(ctx.type_name) * 2654435761; | 80 size_t type_hash = reinterpret_cast<size_t>(ctx.type_name) * 2654435761; |
70 | 81 |
71 // Multiply one side to break the commutativity of +. Multiplication with a | 82 // Multiply one side to break the commutativity of +. Multiplication with a |
72 // number coprime to |numeric_limits<size_t>::max() + 1| is bijective so | 83 // number coprime to |numeric_limits<size_t>::max() + 1| is bijective so |
73 // randomness is preserved. | 84 // randomness is preserved. |
74 return (backtrace_hash * 3) + type_hash; | 85 return (backtrace_hash * 3) + type_hash; |
75 } | 86 } |
76 | 87 |
77 } // BASE_HASH_NAMESPACE | 88 } // BASE_HASH_NAMESPACE |
OLD | NEW |