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 #ifndef WTF_Allocator_h | 5 #ifndef WTF_Allocator_h |
6 #define WTF_Allocator_h | 6 #define WTF_Allocator_h |
7 | 7 |
8 #include "wtf/Assertions.h" | 8 #include "wtf/Assertions.h" |
9 #include "wtf/Partitions.h" | 9 #include "wtf/Partitions.h" |
10 #include "wtf/StdLibExtras.h" | 10 #include "wtf/StdLibExtras.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 // ... | 87 // ... |
88 // }; | 88 // }; |
89 // | 89 // |
90 // struct Data { | 90 // struct Data { |
91 // USING_FAST_MALLOC(Data) | 91 // USING_FAST_MALLOC(Data) |
92 // public: | 92 // public: |
93 // ... | 93 // ... |
94 // }; | 94 // }; |
95 // | 95 // |
96 | 96 |
97 #define USING_FAST_MALLOC(type) \ | 97 #define USING_FAST_MALLOC_INTERNAL(type, typeName) \ |
98 public: \ | 98 public: \ |
99 void* operator new(size_t, void* p) { return p; } \ | 99 void* operator new(size_t, void* p) { return p; } \ |
100 void* operator new[](size_t, void* p) { return p; } \ | 100 void* operator new[](size_t, void* p) { return p; } \ |
101 \ | 101 \ |
102 void* operator new(size_t size) \ | 102 void* operator new(size_t size) \ |
103 { \ | 103 { \ |
104 return ::WTF::Partitions::fastMalloc(size, WTF_HEAP_PROFILER_TYPE_NAME(t ype)); \ | 104 return ::WTF::Partitions::fastMalloc(size, typeName); \ |
105 } \ | 105 } \ |
106 \ | 106 \ |
107 void operator delete(void* p) \ | 107 void operator delete(void* p) \ |
108 { \ | 108 { \ |
109 ::WTF::Partitions::fastFree(p); \ | 109 ::WTF::Partitions::fastFree(p); \ |
110 } \ | 110 } \ |
111 \ | 111 \ |
112 void* operator new[](size_t size) \ | 112 void* operator new[](size_t size) \ |
113 { \ | 113 { \ |
114 return ::WTF::Partitions::fastMalloc(size, WTF_HEAP_PROFILER_TYPE_NAME(t ype)); \ | 114 return ::WTF::Partitions::fastMalloc(size, typeName); \ |
115 } \ | 115 } \ |
116 \ | 116 \ |
117 void operator delete[](void* p) \ | 117 void operator delete[](void* p) \ |
118 { \ | 118 { \ |
119 ::WTF::Partitions::fastFree(p); \ | 119 ::WTF::Partitions::fastFree(p); \ |
120 } \ | 120 } \ |
121 void* operator new(size_t, NotNullTag, void* location) \ | 121 void* operator new(size_t, NotNullTag, void* location) \ |
122 { \ | 122 { \ |
123 ASSERT(location); \ | 123 ASSERT(location); \ |
124 return location; \ | 124 return location; \ |
125 } \ | 125 } \ |
126 static const char* classNameForAllocator() \ | 126 static const char* classNameForAllocator() \ |
127 { \ | 127 { \ |
128 return #type; \ | 128 return #type; \ |
129 } \ | 129 } \ |
130 private: \ | 130 private: \ |
131 typedef int __thisIsHereToForceASemicolonAfterThisMacro | 131 typedef int __thisIsHereToForceASemicolonAfterThisMacro |
132 | 132 |
133 #define USING_FAST_MALLOC(type) USING_FAST_MALLOC_INTERNAL(type, WTF_HEAP_PROFIL ER_TYPE_NAME(type)) | |
134 #define USING_FAST_MALLOC_WITH_TYPE_NAME(type) USING_FAST_MALLOC_INTERNAL(type, #type) | |
haraken
2015/11/27 15:36:10
Add a comment and explain the difference of these
Ruud van Asseldonk
2015/11/27 16:31:19
Done.
| |
135 | |
133 } // namespace WTF | 136 } // namespace WTF |
134 | 137 |
135 #endif /* WTF_Allocator_h */ | 138 #endif /* WTF_Allocator_h */ |
OLD | NEW |