| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef TerminatedArray_h | 4 #ifndef TerminatedArray_h |
| 5 #define TerminatedArray_h | 5 #define TerminatedArray_h |
| 6 | 6 |
| 7 #include "wtf/Allocator.h" | 7 #include "wtf/Allocator.h" |
| 8 #include "wtf/OwnPtr.h" | 8 #include "wtf/OwnPtr.h" |
| 9 #include "wtf/allocator/Partitions.h" | 9 #include "wtf/allocator/Partitions.h" |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 void operator delete(void* p) { ::WTF::Partitions::fastFree(p); } | 70 void operator delete(void* p) { ::WTF::Partitions::fastFree(p); } |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 // Allocator describes how TerminatedArrayBuilder should create new instance
s | 73 // Allocator describes how TerminatedArrayBuilder should create new instance
s |
| 74 // of TerminateArray and manage their lifetimes. | 74 // of TerminateArray and manage their lifetimes. |
| 75 struct Allocator { | 75 struct Allocator { |
| 76 STATIC_ONLY(Allocator); | 76 STATIC_ONLY(Allocator); |
| 77 typedef PassOwnPtr<TerminatedArray> PassPtr; | 77 typedef PassOwnPtr<TerminatedArray> PassPtr; |
| 78 typedef OwnPtr<TerminatedArray> Ptr; | 78 typedef OwnPtr<TerminatedArray> Ptr; |
| 79 | 79 |
| 80 static PassPtr release(Ptr& ptr) |
| 81 { |
| 82 return ptr.release(); |
| 83 } |
| 84 |
| 80 static PassPtr create(size_t capacity) | 85 static PassPtr create(size_t capacity) |
| 81 { | 86 { |
| 82 return adoptPtr(static_cast<TerminatedArray*>(WTF::Partitions::fastM
alloc(capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)))); | 87 return adoptPtr(static_cast<TerminatedArray*>(WTF::Partitions::fastM
alloc(capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)))); |
| 83 } | 88 } |
| 84 | 89 |
| 85 static PassPtr resize(PassPtr ptr, size_t capacity) | 90 static PassPtr resize(Ptr ptr, size_t capacity) |
| 86 { | 91 { |
| 87 return adoptPtr(static_cast<TerminatedArray*>(WTF::Partitions::fastR
ealloc(ptr.leakPtr(), capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)))); | 92 return adoptPtr(static_cast<TerminatedArray*>(WTF::Partitions::fastR
ealloc(ptr.leakPtr(), capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)))); |
| 88 } | 93 } |
| 89 }; | 94 }; |
| 90 | 95 |
| 91 // Prohibit construction. Allocator makes TerminatedArray instances for | 96 // Prohibit construction. Allocator makes TerminatedArray instances for |
| 92 // TerminatedArrayBuilder by pointer casting. | 97 // TerminatedArrayBuilder by pointer casting. |
| 93 TerminatedArray(); | 98 TerminatedArray(); |
| 94 | 99 |
| 95 template<typename, template <typename> class> friend class TerminatedArrayBu
ilder; | 100 template<typename, template <typename> class> friend class TerminatedArrayBu
ilder; |
| 96 }; | 101 }; |
| 97 | 102 |
| 98 } // namespace WTF | 103 } // namespace WTF |
| 99 | 104 |
| 100 using WTF::TerminatedArray; | 105 using WTF::TerminatedArray; |
| 101 | 106 |
| 102 #endif // TerminatedArray_h | 107 #endif // TerminatedArray_h |
| OLD | NEW |