| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #ifndef CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ | 15 #ifndef CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ |
| 16 #define CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ | 16 #define CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ |
| 17 | 17 |
| 18 #include <stddef.h> | 18 #include <stddef.h> |
| 19 | 19 |
| 20 #include <limits> | 20 #include <limits> |
| 21 #include <memory> | 21 #include <memory> |
| 22 #include <new> | 22 #include <new> |
| 23 #include <utility> | 23 #include <utility> |
| 24 #include <vector> | 24 #include <vector> |
| 25 | 25 |
| 26 #include "base/compiler_specific.h" | 26 #include "base/compiler_specific.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "util/stdlib/cxx.h" |
| 28 | 29 |
| 29 #if defined(COMPILER_MSVC) && _MSC_VER < 1900 | 30 #if defined(COMPILER_MSVC) && _MSC_VER < 1900 |
| 30 #define CRASHPAD_NOEXCEPT _NOEXCEPT | 31 #define CRASHPAD_NOEXCEPT _NOEXCEPT |
| 31 #else | 32 #else |
| 32 #define CRASHPAD_NOEXCEPT noexcept | 33 #define CRASHPAD_NOEXCEPT noexcept |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 namespace crashpad { | 36 namespace crashpad { |
| 36 namespace internal { | 37 namespace internal { |
| 37 | 38 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 73 |
| 73 AlignedAllocator() CRASHPAD_NOEXCEPT {} | 74 AlignedAllocator() CRASHPAD_NOEXCEPT {} |
| 74 AlignedAllocator(const AlignedAllocator& other) CRASHPAD_NOEXCEPT {} | 75 AlignedAllocator(const AlignedAllocator& other) CRASHPAD_NOEXCEPT {} |
| 75 | 76 |
| 76 template <typename U> | 77 template <typename U> |
| 77 AlignedAllocator(const AlignedAllocator<U, Alignment>& other) | 78 AlignedAllocator(const AlignedAllocator<U, Alignment>& other) |
| 78 CRASHPAD_NOEXCEPT {} | 79 CRASHPAD_NOEXCEPT {} |
| 79 | 80 |
| 80 ~AlignedAllocator() {} | 81 ~AlignedAllocator() {} |
| 81 | 82 |
| 82 pointer address(reference x) CRASHPAD_NOEXCEPT { return &x; } | 83 pointer address(reference x) const CRASHPAD_NOEXCEPT { return &x; } |
| 83 const_pointer address(const_reference x) CRASHPAD_NOEXCEPT { return &x; } | 84 const_pointer address(const_reference x) const CRASHPAD_NOEXCEPT { |
| 85 return &x; |
| 86 } |
| 84 | 87 |
| 85 pointer allocate(size_type n, std::allocator<void>::const_pointer hint = 0) { | 88 pointer allocate(size_type n, std::allocator<void>::const_pointer hint = 0) { |
| 86 return reinterpret_cast<pointer>( | 89 return reinterpret_cast<pointer>( |
| 87 internal::AlignedAllocate(Alignment, sizeof(value_type) * n)); | 90 internal::AlignedAllocate(Alignment, sizeof(value_type) * n)); |
| 88 } | 91 } |
| 89 | 92 |
| 90 void deallocate(pointer p, size_type n) { internal::AlignedFree(p); } | 93 void deallocate(pointer p, size_type n) { internal::AlignedFree(p); } |
| 91 | 94 |
| 92 size_type max_size() const CRASHPAD_NOEXCEPT { | 95 size_type max_size() const CRASHPAD_NOEXCEPT { |
| 93 return std::numeric_limits<size_type>::max() / sizeof(value_type); | 96 return std::numeric_limits<size_type>::max() / sizeof(value_type); |
| 94 } | 97 } |
| 95 | 98 |
| 99 #if CXX_LIBRARY_VERSION < 2011 |
| 100 void construct(pointer p, const T& val) { |
| 101 new (reinterpret_cast<void*>(p)) T(val); |
| 102 } |
| 103 #else |
| 96 template <class U, class... Args> | 104 template <class U, class... Args> |
| 97 void construct(U* p, Args&&... args) { | 105 void construct(U* p, Args&&... args) { |
| 98 new (reinterpret_cast<void*>(p)) U(std::forward<Args>(args)...); | 106 new (reinterpret_cast<void*>(p)) U(std::forward<Args>(args)...); |
| 99 } | 107 } |
| 108 #endif |
| 100 | 109 |
| 101 template <class U> | 110 template <class U> |
| 102 void destroy(U* p) { | 111 void destroy(U* p) { |
| 103 p->~U(); | 112 p->~U(); |
| 104 } | 113 } |
| 105 }; | 114 }; |
| 106 | 115 |
| 107 template <class T1, class T2, size_t Alignment> | 116 template <class T1, class T2, size_t Alignment> |
| 108 bool operator==(const AlignedAllocator<T1, Alignment>& lhs, | 117 bool operator==(const AlignedAllocator<T1, Alignment>& lhs, |
| 109 const AlignedAllocator<T2, Alignment>& rhs) CRASHPAD_NOEXCEPT { | 118 const AlignedAllocator<T2, Alignment>& rhs) CRASHPAD_NOEXCEPT { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 122 //! guarantee. \a Alignment must be a power of 2. If \a Alignment is not | 131 //! guarantee. \a Alignment must be a power of 2. If \a Alignment is not |
| 123 //! specified, the default alignment for type \a T is used. | 132 //! specified, the default alignment for type \a T is used. |
| 124 template <typename T, size_t Alignment = ALIGNOF(T)> | 133 template <typename T, size_t Alignment = ALIGNOF(T)> |
| 125 using AlignedVector = std::vector<T, AlignedAllocator<T, Alignment>>; | 134 using AlignedVector = std::vector<T, AlignedAllocator<T, Alignment>>; |
| 126 | 135 |
| 127 } // namespace crashpad | 136 } // namespace crashpad |
| 128 | 137 |
| 129 #undef CRASHPAD_NOEXCEPT | 138 #undef CRASHPAD_NOEXCEPT |
| 130 | 139 |
| 131 #endif // CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ | 140 #endif // CRASHPAD_UTIL_STDLIB_ALIGNED_ALLOCATOR_H_ |
| OLD | NEW |