/root/bitcoin/src/prevector.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2015-2022 The Bitcoin Core developers |
2 | | // Distributed under the MIT software license, see the accompanying |
3 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | | |
5 | | #ifndef BITCOIN_PREVECTOR_H |
6 | | #define BITCOIN_PREVECTOR_H |
7 | | |
8 | | #include <algorithm> |
9 | | #include <cassert> |
10 | | #include <cstddef> |
11 | | #include <cstdint> |
12 | | #include <cstdlib> |
13 | | #include <cstring> |
14 | | #include <iterator> |
15 | | #include <type_traits> |
16 | | #include <utility> |
17 | | |
18 | | /** Implements a drop-in replacement for std::vector<T> which stores up to N |
19 | | * elements directly (without heap allocation). The types Size and Diff are |
20 | | * used to store element counts, and can be any unsigned + signed type. |
21 | | * |
22 | | * Storage layout is either: |
23 | | * - Direct allocation: |
24 | | * - Size _size: the number of used elements (between 0 and N) |
25 | | * - T direct[N]: an array of N elements of type T |
26 | | * (only the first _size are initialized). |
27 | | * - Indirect allocation: |
28 | | * - Size _size: the number of used elements plus N + 1 |
29 | | * - Size capacity: the number of allocated elements |
30 | | * - T* indirect: a pointer to an array of capacity elements of type T |
31 | | * (only the first _size are initialized). |
32 | | * |
33 | | * The data type T must be movable by memmove/realloc(). Once we switch to C++, |
34 | | * move constructors can be used instead. |
35 | | */ |
36 | | template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t> |
37 | | class prevector { |
38 | | static_assert(std::is_trivially_copyable_v<T>); |
39 | | |
40 | | public: |
41 | | typedef Size size_type; |
42 | | typedef Diff difference_type; |
43 | | typedef T value_type; |
44 | | typedef value_type& reference; |
45 | | typedef const value_type& const_reference; |
46 | | typedef value_type* pointer; |
47 | | typedef const value_type* const_pointer; |
48 | | |
49 | | class iterator { |
50 | | T* ptr{}; |
51 | | public: |
52 | | typedef Diff difference_type; |
53 | | typedef T* pointer; |
54 | | typedef T& reference; |
55 | | using element_type = T; |
56 | | using iterator_category = std::contiguous_iterator_tag; |
57 | | iterator() = default; |
58 | 5.77k | iterator(T* ptr_) : ptr(ptr_) {} Unexecuted instantiation: _ZN9prevectorILj16EhjiE8iteratorC2EPh _ZN9prevectorILj28EhjiE8iteratorC2EPh Line | Count | Source | 58 | 5.77k | iterator(T* ptr_) : ptr(ptr_) {} |
Unexecuted instantiation: _ZN9prevectorILj8EijiE8iteratorC2EPi Unexecuted instantiation: _ZN9prevectorILj33EhjiE8iteratorC2EPh Unexecuted instantiation: _ZN9prevectorILj35EhjiE8iteratorC2EPh |
59 | 4.84k | T& operator*() const { return *ptr; } _ZNK9prevectorILj28EhjiE8iteratordeEv Line | Count | Source | 59 | 4.84k | T& operator*() const { return *ptr; } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE8iteratordeEv Unexecuted instantiation: _ZNK9prevectorILj8EijiE8iteratordeEv Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8iteratordeEv Unexecuted instantiation: _ZNK9prevectorILj35EhjiE8iteratordeEv |
60 | | T* operator->() const { return ptr; } |
61 | | T& operator[](size_type pos) const { return ptr[pos]; } |
62 | 0 | iterator& operator++() { ptr++; return *this; } |
63 | | iterator& operator--() { ptr--; return *this; } |
64 | | iterator operator++(int) { iterator copy(*this); ++(*this); return copy; } |
65 | | iterator operator--(int) { iterator copy(*this); --(*this); return copy; } |
66 | 2.42k | difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); } _ZmiN9prevectorILj28EhjiE8iteratorES1_ Line | Count | Source | 66 | 2.42k | difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); } |
Unexecuted instantiation: _ZmiN9prevectorILj16EhjiE8iteratorES1_ Unexecuted instantiation: _ZmiN9prevectorILj8EijiE8iteratorES1_ Unexecuted instantiation: _ZmiN9prevectorILj33EhjiE8iteratorES1_ Unexecuted instantiation: _ZmiN9prevectorILj35EhjiE8iteratorES1_ |
67 | 0 | iterator operator+(size_type n) const { return iterator(ptr + n); } Unexecuted instantiation: _ZNK9prevectorILj28EhjiE8iteratorplEj Unexecuted instantiation: _ZNK9prevectorILj8EijiE8iteratorplEj Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8iteratorplEj |
68 | | iterator friend operator+(size_type n, iterator x) { return x + n; } |
69 | | iterator& operator+=(size_type n) { ptr += n; return *this; } |
70 | 0 | iterator operator-(size_type n) const { return iterator(ptr - n); } |
71 | | iterator& operator-=(size_type n) { ptr -= n; return *this; } |
72 | | bool operator==(iterator x) const { return ptr == x.ptr; } |
73 | 0 | bool operator!=(iterator x) const { return ptr != x.ptr; } |
74 | | bool operator>=(iterator x) const { return ptr >= x.ptr; } |
75 | | bool operator<=(iterator x) const { return ptr <= x.ptr; } |
76 | | bool operator>(iterator x) const { return ptr > x.ptr; } |
77 | | bool operator<(iterator x) const { return ptr < x.ptr; } |
78 | | }; |
79 | | |
80 | | class reverse_iterator { |
81 | | T* ptr{}; |
82 | | public: |
83 | | typedef Diff difference_type; |
84 | | typedef T value_type; |
85 | | typedef T* pointer; |
86 | | typedef T& reference; |
87 | | typedef std::bidirectional_iterator_tag iterator_category; |
88 | | reverse_iterator() = default; |
89 | | reverse_iterator(T* ptr_) : ptr(ptr_) {} |
90 | | T& operator*() const { return *ptr; } |
91 | | T* operator->() const { return ptr; } |
92 | | reverse_iterator& operator--() { ptr++; return *this; } |
93 | | reverse_iterator& operator++() { ptr--; return *this; } |
94 | | reverse_iterator operator++(int) { reverse_iterator copy(*this); ++(*this); return copy; } |
95 | | reverse_iterator operator--(int) { reverse_iterator copy(*this); --(*this); return copy; } |
96 | | bool operator==(reverse_iterator x) const { return ptr == x.ptr; } |
97 | | bool operator!=(reverse_iterator x) const { return ptr != x.ptr; } |
98 | | }; |
99 | | |
100 | | class const_iterator { |
101 | | const T* ptr{}; |
102 | | public: |
103 | | typedef Diff difference_type; |
104 | | typedef const T* pointer; |
105 | | typedef const T& reference; |
106 | | using element_type = const T; |
107 | | using iterator_category = std::contiguous_iterator_tag; |
108 | | const_iterator() = default; |
109 | 3.94M | const_iterator(const T* ptr_) : ptr(ptr_) {} Unexecuted instantiation: _ZN9prevectorILj16EhjiE14const_iteratorC2EPKh _ZN9prevectorILj28EhjiE14const_iteratorC2EPKh Line | Count | Source | 109 | 3.94M | const_iterator(const T* ptr_) : ptr(ptr_) {} |
Unexecuted instantiation: _ZN9prevectorILj8EijiE14const_iteratorC2EPKi |
110 | 0 | const_iterator(iterator x) : ptr(&(*x)) {} |
111 | 8.56M | const T& operator*() const { return *ptr; } _ZNK9prevectorILj28EhjiE14const_iteratordeEv Line | Count | Source | 111 | 8.56M | const T& operator*() const { return *ptr; } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE14const_iteratordeEv Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratordeEv |
112 | | const T* operator->() const { return ptr; } |
113 | 0 | const T& operator[](size_type pos) const { return ptr[pos]; } Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratorixEj Unexecuted instantiation: _ZNK9prevectorILj28EhjiE14const_iteratorixEj |
114 | 8.56M | const_iterator& operator++() { ptr++; return *this; } _ZN9prevectorILj28EhjiE14const_iteratorppEv Line | Count | Source | 114 | 8.56M | const_iterator& operator++() { ptr++; return *this; } |
Unexecuted instantiation: _ZN9prevectorILj16EhjiE14const_iteratorppEv Unexecuted instantiation: _ZN9prevectorILj8EijiE14const_iteratorppEv |
115 | 0 | const_iterator& operator--() { ptr--; return *this; } Unexecuted instantiation: _ZN9prevectorILj8EijiE14const_iteratormmEv Unexecuted instantiation: _ZN9prevectorILj28EhjiE14const_iteratormmEv |
116 | 0 | const_iterator operator++(int) { const_iterator copy(*this); ++(*this); return copy; } |
117 | | const_iterator operator--(int) { const_iterator copy(*this); --(*this); return copy; } |
118 | 850 | difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); } Unexecuted instantiation: _ZmiN9prevectorILj16EhjiE14const_iteratorES1_ _ZmiN9prevectorILj28EhjiE14const_iteratorES1_ Line | Count | Source | 118 | 850 | difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); } |
Unexecuted instantiation: _ZmiN9prevectorILj8EijiE14const_iteratorES1_ |
119 | 0 | const_iterator operator+(size_type n) const { return const_iterator(ptr + n); } Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratorplEj Unexecuted instantiation: _ZNK9prevectorILj28EhjiE14const_iteratorplEj |
120 | | const_iterator friend operator+(size_type n, const_iterator x) { return x + n; } |
121 | 0 | const_iterator& operator+=(size_type n) { ptr += n; return *this; } |
122 | 0 | const_iterator operator-(size_type n) const { return const_iterator(ptr - n); } Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratormiEj Unexecuted instantiation: _ZNK9prevectorILj28EhjiE14const_iteratormiEj |
123 | | const_iterator& operator-=(size_type n) { ptr -= n; return *this; } |
124 | 0 | bool operator==(const_iterator x) const { return ptr == x.ptr; } Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratoreqES1_ Unexecuted instantiation: _ZNK9prevectorILj16EhjiE14const_iteratoreqES1_ Unexecuted instantiation: _ZNK9prevectorILj28EhjiE14const_iteratoreqES1_ |
125 | 10.5M | bool operator!=(const_iterator x) const { return ptr != x.ptr; } _ZNK9prevectorILj28EhjiE14const_iteratorneES1_ Line | Count | Source | 125 | 10.5M | bool operator!=(const_iterator x) const { return ptr != x.ptr; } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE14const_iteratorneES1_ Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratorneES1_ |
126 | 0 | bool operator>=(const_iterator x) const { return ptr >= x.ptr; } |
127 | | bool operator<=(const_iterator x) const { return ptr <= x.ptr; } |
128 | | bool operator>(const_iterator x) const { return ptr > x.ptr; } |
129 | 0 | bool operator<(const_iterator x) const { return ptr < x.ptr; } |
130 | | }; |
131 | | |
132 | | class const_reverse_iterator { |
133 | | const T* ptr{}; |
134 | | public: |
135 | | typedef Diff difference_type; |
136 | | typedef const T value_type; |
137 | | typedef const T* pointer; |
138 | | typedef const T& reference; |
139 | | typedef std::bidirectional_iterator_tag iterator_category; |
140 | | const_reverse_iterator() = default; |
141 | | const_reverse_iterator(const T* ptr_) : ptr(ptr_) {} |
142 | | const_reverse_iterator(reverse_iterator x) : ptr(&(*x)) {} |
143 | | const T& operator*() const { return *ptr; } |
144 | | const T* operator->() const { return ptr; } |
145 | | const_reverse_iterator& operator--() { ptr++; return *this; } |
146 | | const_reverse_iterator& operator++() { ptr--; return *this; } |
147 | | const_reverse_iterator operator++(int) { const_reverse_iterator copy(*this); ++(*this); return copy; } |
148 | | const_reverse_iterator operator--(int) { const_reverse_iterator copy(*this); --(*this); return copy; } |
149 | | bool operator==(const_reverse_iterator x) const { return ptr == x.ptr; } |
150 | | bool operator!=(const_reverse_iterator x) const { return ptr != x.ptr; } |
151 | | }; |
152 | | |
153 | | private: |
154 | | #pragma pack(push, 1) |
155 | | union direct_or_indirect { |
156 | | char direct[sizeof(T) * N]; |
157 | | struct { |
158 | | char* indirect; |
159 | | size_type capacity; |
160 | | } indirect_contents; |
161 | | }; |
162 | | #pragma pack(pop) |
163 | | alignas(char*) direct_or_indirect _union = {}; |
164 | | size_type _size = 0; |
165 | | |
166 | | static_assert(alignof(char*) % alignof(size_type) == 0 && sizeof(char*) % alignof(size_type) == 0, "size_type cannot have more restrictive alignment requirement than pointer"); |
167 | | static_assert(alignof(char*) % alignof(T) == 0, "value_type T cannot have more restrictive alignment requirement than pointer"); |
168 | | |
169 | 1.97M | T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; } _ZN9prevectorILj28EhjiE10direct_ptrEi Line | Count | Source | 169 | 1.97M | T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; } |
Unexecuted instantiation: _ZN9prevectorILj33EhjiE10direct_ptrEi Unexecuted instantiation: _ZN9prevectorILj16EhjiE10direct_ptrEi Unexecuted instantiation: _ZN9prevectorILj8EijiE10direct_ptrEi Unexecuted instantiation: _ZN9prevectorILj35EhjiE10direct_ptrEi |
170 | 3.93M | const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; } _ZNK9prevectorILj28EhjiE10direct_ptrEi Line | Count | Source | 170 | 3.93M | const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE10direct_ptrEi Unexecuted instantiation: _ZNK9prevectorILj8EijiE10direct_ptrEi Unexecuted instantiation: _ZNK9prevectorILj33EhjiE10direct_ptrEi |
171 | 2.92k | T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; } _ZN9prevectorILj28EhjiE12indirect_ptrEi Line | Count | Source | 171 | 2.92k | T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; } |
Unexecuted instantiation: _ZN9prevectorILj33EhjiE12indirect_ptrEi Unexecuted instantiation: _ZN9prevectorILj16EhjiE12indirect_ptrEi Unexecuted instantiation: _ZN9prevectorILj8EijiE12indirect_ptrEi Unexecuted instantiation: _ZN9prevectorILj35EhjiE12indirect_ptrEi |
172 | 5.85k | const T* indirect_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.indirect_contents.indirect) + pos; } _ZNK9prevectorILj28EhjiE12indirect_ptrEi Line | Count | Source | 172 | 5.85k | const T* indirect_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.indirect_contents.indirect) + pos; } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE12indirect_ptrEi Unexecuted instantiation: _ZNK9prevectorILj8EijiE12indirect_ptrEi Unexecuted instantiation: _ZNK9prevectorILj33EhjiE12indirect_ptrEi |
173 | 34.8M | bool is_direct() const { return _size <= N; } _ZNK9prevectorILj28EhjiE9is_directEv Line | Count | Source | 173 | 34.8M | bool is_direct() const { return _size <= N; } |
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE9is_directEv Unexecuted instantiation: _ZNK9prevectorILj16EhjiE9is_directEv Unexecuted instantiation: _ZNK9prevectorILj8EijiE9is_directEv Unexecuted instantiation: _ZNK9prevectorILj35EhjiE9is_directEv |
174 | | |
175 | 5.29M | void change_capacity(size_type new_capacity) { |
176 | 5.29M | if (new_capacity <= N) { |
177 | 5.29M | if (!is_direct()) { |
178 | 0 | T* indirect = indirect_ptr(0); |
179 | 0 | T* src = indirect; |
180 | 0 | T* dst = direct_ptr(0); |
181 | 0 | memcpy(dst, src, size() * sizeof(T)); |
182 | 0 | free(indirect); |
183 | 0 | _size -= N + 1; |
184 | 0 | } |
185 | 5.29M | } else { |
186 | 2.92k | if (!is_direct()) { |
187 | | /* FIXME: Because malloc/realloc here won't call new_handler if allocation fails, assert |
188 | | success. These should instead use an allocator or new/delete so that handlers |
189 | | are called as necessary, but performance would be slightly degraded by doing so. */ |
190 | 0 | _union.indirect_contents.indirect = static_cast<char*>(realloc(_union.indirect_contents.indirect, ((size_t)sizeof(T)) * new_capacity)); |
191 | 0 | assert(_union.indirect_contents.indirect); |
192 | 0 | _union.indirect_contents.capacity = new_capacity; |
193 | 2.92k | } else { |
194 | 2.92k | char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity)); |
195 | 2.92k | assert(new_indirect); |
196 | 2.92k | T* src = direct_ptr(0); |
197 | 2.92k | T* dst = reinterpret_cast<T*>(new_indirect); |
198 | 2.92k | memcpy(dst, src, size() * sizeof(T)); |
199 | 2.92k | _union.indirect_contents.indirect = new_indirect; |
200 | 2.92k | _union.indirect_contents.capacity = new_capacity; |
201 | 2.92k | _size += N + 1; |
202 | 2.92k | } |
203 | 2.92k | } |
204 | 5.29M | } _ZN9prevectorILj28EhjiE15change_capacityEj Line | Count | Source | 175 | 5.29M | void change_capacity(size_type new_capacity) { | 176 | 5.29M | if (new_capacity <= N) { | 177 | 5.29M | if (!is_direct()) { | 178 | 0 | T* indirect = indirect_ptr(0); | 179 | 0 | T* src = indirect; | 180 | 0 | T* dst = direct_ptr(0); | 181 | 0 | memcpy(dst, src, size() * sizeof(T)); | 182 | 0 | free(indirect); | 183 | 0 | _size -= N + 1; | 184 | 0 | } | 185 | 5.29M | } else { | 186 | 2.92k | if (!is_direct()) { | 187 | | /* FIXME: Because malloc/realloc here won't call new_handler if allocation fails, assert | 188 | | success. These should instead use an allocator or new/delete so that handlers | 189 | | are called as necessary, but performance would be slightly degraded by doing so. */ | 190 | 0 | _union.indirect_contents.indirect = static_cast<char*>(realloc(_union.indirect_contents.indirect, ((size_t)sizeof(T)) * new_capacity)); | 191 | 0 | assert(_union.indirect_contents.indirect); | 192 | 0 | _union.indirect_contents.capacity = new_capacity; | 193 | 2.92k | } else { | 194 | 2.92k | char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity)); | 195 | 2.92k | assert(new_indirect); | 196 | 2.92k | T* src = direct_ptr(0); | 197 | 2.92k | T* dst = reinterpret_cast<T*>(new_indirect); | 198 | 2.92k | memcpy(dst, src, size() * sizeof(T)); | 199 | 2.92k | _union.indirect_contents.indirect = new_indirect; | 200 | 2.92k | _union.indirect_contents.capacity = new_capacity; | 201 | 2.92k | _size += N + 1; | 202 | 2.92k | } | 203 | 2.92k | } | 204 | 5.29M | } |
Unexecuted instantiation: _ZN9prevectorILj16EhjiE15change_capacityEj Unexecuted instantiation: _ZN9prevectorILj33EhjiE15change_capacityEj Unexecuted instantiation: _ZN9prevectorILj8EijiE15change_capacityEj Unexecuted instantiation: _ZN9prevectorILj35EhjiE15change_capacityEj |
205 | | |
206 | 1.97M | T* item_ptr(difference_type pos) { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); } _ZN9prevectorILj28EhjiE8item_ptrEi Line | Count | Source | 206 | 1.97M | T* item_ptr(difference_type pos) { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); } |
Unexecuted instantiation: _ZN9prevectorILj33EhjiE8item_ptrEi Unexecuted instantiation: _ZN9prevectorILj16EhjiE8item_ptrEi Unexecuted instantiation: _ZN9prevectorILj8EijiE8item_ptrEi Unexecuted instantiation: _ZN9prevectorILj35EhjiE8item_ptrEi |
207 | 3.94M | const T* item_ptr(difference_type pos) const { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); } _ZNK9prevectorILj28EhjiE8item_ptrEi Line | Count | Source | 207 | 3.94M | const T* item_ptr(difference_type pos) const { return is_direct() ? direct_ptr(pos) : indirect_ptr(pos); } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE8item_ptrEi Unexecuted instantiation: _ZNK9prevectorILj8EijiE8item_ptrEi Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8item_ptrEi |
208 | | |
209 | 0 | void fill(T* dst, ptrdiff_t count, const T& value = T{}) { |
210 | 0 | std::fill_n(dst, count, value); |
211 | 0 | } Unexecuted instantiation: _ZN9prevectorILj28EhjiE4fillEPhlRKh Unexecuted instantiation: _ZN9prevectorILj16EhjiE4fillEPhlRKh Unexecuted instantiation: _ZN9prevectorILj33EhjiE4fillEPhlRKh Unexecuted instantiation: _ZN9prevectorILj8EijiE4fillEPilRKi |
212 | | |
213 | | template <std::input_iterator InputIterator> |
214 | 1.97M | void fill(T* dst, InputIterator first, InputIterator last) { |
215 | 13.3M | while (first != last) { |
216 | 11.4M | new(static_cast<void*>(dst)) T(*first); |
217 | 11.4M | ++dst; |
218 | 11.4M | ++first; |
219 | 11.4M | } |
220 | 1.97M | } _ZN9prevectorILj28EhjiE4fillITkSt14input_iteratorPKhEEvPhT_S5_ Line | Count | Source | 214 | 650 | void fill(T* dst, InputIterator first, InputIterator last) { | 215 | 1.95k | while (first != last) { | 216 | 1.30k | new(static_cast<void*>(dst)) T(*first); | 217 | 1.30k | ++dst; | 218 | 1.30k | ++first; | 219 | 1.30k | } | 220 | 650 | } |
_ZN9prevectorILj28EhjiE4fillITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPKhSt4spanIS4_Lm18446744073709551615EEEEEEvPhT_SA_ Line | Count | Source | 214 | 850 | void fill(T* dst, InputIterator first, InputIterator last) { | 215 | 2.85M | while (first != last) { | 216 | 2.85M | new(static_cast<void*>(dst)) T(*first); | 217 | 2.85M | ++dst; | 218 | 2.85M | ++first; | 219 | 2.85M | } | 220 | 850 | } |
_ZN9prevectorILj28EhjiE4fillITkSt14input_iteratorNS0_14const_iteratorEEEvPhT_S4_ Line | Count | Source | 214 | 1.97M | void fill(T* dst, InputIterator first, InputIterator last) { | 215 | 10.5M | while (first != last) { | 216 | 8.56M | new(static_cast<void*>(dst)) T(*first); | 217 | 8.56M | ++dst; | 218 | 8.56M | ++first; | 219 | 8.56M | } | 220 | 1.97M | } |
Unexecuted instantiation: _ZN9prevectorILj16EhjiE4fillITkSt14input_iteratorNS0_14const_iteratorEEEvPhT_S4_ Unexecuted instantiation: _ZN9prevectorILj28EhjiE4fillITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPKhSt6vectorIhSaIhEEEEEEvPhT_SB_ Unexecuted instantiation: _ZN9prevectorILj28EhjiE4fillITkSt14input_iteratorNS0_8iteratorEEEvPhT_S4_ Unexecuted instantiation: _ZN9prevectorILj8EijiE4fillITkSt14input_iteratorPiEEvS2_T_S3_ Unexecuted instantiation: _ZN9prevectorILj8EijiE4fillITkSt14input_iteratorNS0_14const_iteratorEEEvPiT_S4_ Unexecuted instantiation: _ZN9prevectorILj8EijiE4fillITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPKiSt6vectorIiSaIiEEEEEEvPiT_SB_ Unexecuted instantiation: _ZN9prevectorILj33EhjiE4fillITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPKhSt6vectorIhSaIhEEEEEEvPhT_SB_ Unexecuted instantiation: _ZN9prevectorILj28EhjiE4fillITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPhSt6vectorIhSaIhEEEEEEvS4_T_S9_ Unexecuted instantiation: _ZN9prevectorILj16EhjiE4fillITkSt14input_iteratorPKhEEvPhT_S5_ Unexecuted instantiation: _ZN9prevectorILj16EhjiE4fillITkSt14input_iteratorPhEEvS2_T_S3_ Unexecuted instantiation: _ZN9prevectorILj16EhjiE4fillITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPhSt6vectorIhSaIhEEEEEEvS4_T_S9_ Unexecuted instantiation: _ZN9prevectorILj35EhjiE4fillITkSt14input_iteratorPKhEEvPhT_S5_ Unexecuted instantiation: _ZN9prevectorILj35EhjiE4fillITkSt14input_iteratorPhEEvS2_T_S3_ |
221 | | |
222 | | public: |
223 | 0 | void assign(size_type n, const T& val) { |
224 | 0 | clear(); |
225 | 0 | if (capacity() < n) { |
226 | 0 | change_capacity(n); |
227 | 0 | } |
228 | 0 | _size += n; |
229 | 0 | fill(item_ptr(0), n, val); |
230 | 0 | } Unexecuted instantiation: _ZN9prevectorILj16EhjiE6assignEjRKh Unexecuted instantiation: _ZN9prevectorILj8EijiE6assignEjRKi |
231 | | |
232 | | template <std::input_iterator InputIterator> |
233 | 850 | void assign(InputIterator first, InputIterator last) { |
234 | 850 | size_type n = last - first; |
235 | 850 | clear(); |
236 | 850 | if (capacity() < n) { |
237 | 731 | change_capacity(n); |
238 | 731 | } |
239 | 850 | _size += n; |
240 | 850 | fill(item_ptr(0), first, last); |
241 | 850 | } Unexecuted instantiation: _ZN9prevectorILj16EhjiE6assignITkSt14input_iteratorNS0_14const_iteratorEEEvT_S3_ _ZN9prevectorILj28EhjiE6assignITkSt14input_iteratorNS0_14const_iteratorEEEvT_S3_ Line | Count | Source | 233 | 850 | void assign(InputIterator first, InputIterator last) { | 234 | 850 | size_type n = last - first; | 235 | 850 | clear(); | 236 | 850 | if (capacity() < n) { | 237 | 731 | change_capacity(n); | 238 | 731 | } | 239 | 850 | _size += n; | 240 | 850 | fill(item_ptr(0), first, last); | 241 | 850 | } |
Unexecuted instantiation: _ZN9prevectorILj8EijiE6assignITkSt14input_iteratorNS0_14const_iteratorEEEvT_S3_ Unexecuted instantiation: _ZN9prevectorILj33EhjiE6assignITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPKhSt6vectorIhSaIhEEEEEEvT_SA_ Unexecuted instantiation: _ZN9prevectorILj16EhjiE6assignITkSt14input_iteratorPKhEEvT_S4_ Unexecuted instantiation: _ZN9prevectorILj16EhjiE6assignITkSt14input_iteratorPhEEvT_S3_ Unexecuted instantiation: _ZN9prevectorILj16EhjiE6assignITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPhSt6vectorIhSaIhEEEEEEvT_S9_ |
242 | | |
243 | 3.32M | prevector() = default; _ZN9prevectorILj28EhjiEC2Ev Line | Count | Source | 243 | 3.32M | prevector() = default; |
Unexecuted instantiation: _ZN9prevectorILj33EhjiEC2Ev Unexecuted instantiation: _ZN9prevectorILj8EijiEC2Ev |
244 | | |
245 | | explicit prevector(size_type n) { |
246 | | resize(n); |
247 | | } |
248 | | |
249 | 0 | explicit prevector(size_type n, const T& val) { |
250 | 0 | change_capacity(n); |
251 | 0 | _size += n; |
252 | 0 | fill(item_ptr(0), n, val); |
253 | 0 | } Unexecuted instantiation: _ZN9prevectorILj33EhjiEC2EjRKh Unexecuted instantiation: _ZN9prevectorILj16EhjiEC2EjRKh |
254 | | |
255 | | template <std::input_iterator InputIterator> |
256 | 0 | prevector(InputIterator first, InputIterator last) { |
257 | 0 | size_type n = last - first; |
258 | 0 | change_capacity(n); |
259 | 0 | _size += n; |
260 | 0 | fill(item_ptr(0), first, last); |
261 | 0 | } Unexecuted instantiation: _ZN9prevectorILj28EhjiEC2ITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPKhSt6vectorIhSaIhEEEEEET_SA_ Unexecuted instantiation: _ZN9prevectorILj8EijiEC2ITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPKiSt6vectorIiSaIiEEEEEET_SA_ Unexecuted instantiation: _ZN9prevectorILj8EijiEC2ITkSt14input_iteratorNS0_14const_iteratorEEET_S3_ Unexecuted instantiation: _ZN9prevectorILj28EhjiEC2ITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPhSt6vectorIhSaIhEEEEEET_S9_ Unexecuted instantiation: _ZN9prevectorILj35EhjiEC2ITkSt14input_iteratorPKhEET_S4_ Unexecuted instantiation: _ZN9prevectorILj28EhjiEC2ITkSt14input_iteratorPKhEET_S4_ Unexecuted instantiation: _ZN9prevectorILj28EhjiEC2ITkSt14input_iteratorNS0_14const_iteratorEEET_S3_ |
262 | | |
263 | 1.97M | prevector(const prevector<N, T, Size, Diff>& other) { |
264 | 1.97M | size_type n = other.size(); |
265 | 1.97M | change_capacity(n); |
266 | 1.97M | _size += n; |
267 | 1.97M | fill(item_ptr(0), other.begin(), other.end()); |
268 | 1.97M | } Unexecuted instantiation: _ZN9prevectorILj16EhjiEC2ERKS0_ _ZN9prevectorILj28EhjiEC2ERKS0_ Line | Count | Source | 263 | 1.97M | prevector(const prevector<N, T, Size, Diff>& other) { | 264 | 1.97M | size_type n = other.size(); | 265 | 1.97M | change_capacity(n); | 266 | 1.97M | _size += n; | 267 | 1.97M | fill(item_ptr(0), other.begin(), other.end()); | 268 | 1.97M | } |
|
269 | | |
270 | | prevector(prevector<N, T, Size, Diff>&& other) noexcept |
271 | 1.08M | : _union(std::move(other._union)), _size(other._size) |
272 | 1.08M | { |
273 | 1.08M | other._size = 0; |
274 | 1.08M | } Unexecuted instantiation: _ZN9prevectorILj16EhjiEC2EOS0_ _ZN9prevectorILj28EhjiEC2EOS0_ Line | Count | Source | 271 | 1.08M | : _union(std::move(other._union)), _size(other._size) | 272 | 1.08M | { | 273 | 1.08M | other._size = 0; | 274 | 1.08M | } |
|
275 | | |
276 | 850 | prevector& operator=(const prevector<N, T, Size, Diff>& other) { |
277 | 850 | if (&other == this) { |
278 | 0 | return *this; |
279 | 0 | } |
280 | 850 | assign(other.begin(), other.end()); |
281 | 850 | return *this; |
282 | 850 | } Unexecuted instantiation: _ZN9prevectorILj16EhjiEaSERKS0_ _ZN9prevectorILj28EhjiEaSERKS0_ Line | Count | Source | 276 | 850 | prevector& operator=(const prevector<N, T, Size, Diff>& other) { | 277 | 850 | if (&other == this) { | 278 | 0 | return *this; | 279 | 0 | } | 280 | 850 | assign(other.begin(), other.end()); | 281 | 850 | return *this; | 282 | 850 | } |
Unexecuted instantiation: _ZN9prevectorILj8EijiEaSERKS0_ |
283 | | |
284 | 0 | prevector& operator=(prevector<N, T, Size, Diff>&& other) noexcept { |
285 | 0 | if (!is_direct()) { |
286 | 0 | free(_union.indirect_contents.indirect); |
287 | 0 | } |
288 | 0 | _union = std::move(other._union); |
289 | 0 | _size = other._size; |
290 | 0 | other._size = 0; |
291 | 0 | return *this; |
292 | 0 | } Unexecuted instantiation: _ZN9prevectorILj16EhjiEaSEOS0_ Unexecuted instantiation: _ZN9prevectorILj28EhjiEaSEOS0_ Unexecuted instantiation: _ZN9prevectorILj8EijiEaSEOS0_ |
293 | | |
294 | 17.2M | size_type size() const { |
295 | 17.2M | return is_direct() ? _size : _size - N - 1; |
296 | 17.2M | } _ZNK9prevectorILj28EhjiE4sizeEv Line | Count | Source | 294 | 17.2M | size_type size() const { | 295 | 17.2M | return is_direct() ? _size : _size - N - 1; | 296 | 17.2M | } |
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE4sizeEv Unexecuted instantiation: _ZNK9prevectorILj16EhjiE4sizeEv Unexecuted instantiation: _ZNK9prevectorILj8EijiE4sizeEv Unexecuted instantiation: _ZNK9prevectorILj35EhjiE4sizeEv |
297 | | |
298 | 3.32M | bool empty() const { |
299 | 3.32M | return size() == 0; |
300 | 3.32M | } _ZNK9prevectorILj28EhjiE5emptyEv Line | Count | Source | 298 | 3.32M | bool empty() const { | 299 | 3.32M | return size() == 0; | 300 | 3.32M | } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE5emptyEv Unexecuted instantiation: _ZNK9prevectorILj8EijiE5emptyEv |
301 | | |
302 | 2.42k | iterator begin() { return iterator(item_ptr(0)); } _ZN9prevectorILj28EhjiE5beginEv Line | Count | Source | 302 | 2.42k | iterator begin() { return iterator(item_ptr(0)); } |
Unexecuted instantiation: _ZN9prevectorILj8EijiE5beginEv Unexecuted instantiation: _ZN9prevectorILj33EhjiE5beginEv Unexecuted instantiation: _ZN9prevectorILj35EhjiE5beginEv |
303 | 1.97M | const_iterator begin() const { return const_iterator(item_ptr(0)); } _ZNK9prevectorILj28EhjiE5beginEv Line | Count | Source | 303 | 1.97M | const_iterator begin() const { return const_iterator(item_ptr(0)); } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE5beginEv Unexecuted instantiation: _ZNK9prevectorILj8EijiE5beginEv |
304 | 2.42k | iterator end() { return iterator(item_ptr(size())); } _ZN9prevectorILj28EhjiE3endEv Line | Count | Source | 304 | 2.42k | iterator end() { return iterator(item_ptr(size())); } |
Unexecuted instantiation: _ZN9prevectorILj16EhjiE3endEv Unexecuted instantiation: _ZN9prevectorILj8EijiE3endEv Unexecuted instantiation: _ZN9prevectorILj33EhjiE3endEv Unexecuted instantiation: _ZN9prevectorILj35EhjiE3endEv |
305 | 1.97M | const_iterator end() const { return const_iterator(item_ptr(size())); } _ZNK9prevectorILj28EhjiE3endEv Line | Count | Source | 305 | 1.97M | const_iterator end() const { return const_iterator(item_ptr(size())); } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE3endEv Unexecuted instantiation: _ZNK9prevectorILj8EijiE3endEv |
306 | | |
307 | | reverse_iterator rbegin() { return reverse_iterator(item_ptr(size() - 1)); } |
308 | | const_reverse_iterator rbegin() const { return const_reverse_iterator(item_ptr(size() - 1)); } |
309 | | reverse_iterator rend() { return reverse_iterator(item_ptr(-1)); } |
310 | | const_reverse_iterator rend() const { return const_reverse_iterator(item_ptr(-1)); } |
311 | | |
312 | 3.27k | size_t capacity() const { |
313 | 3.27k | if (is_direct()) { |
314 | 3.27k | return N; |
315 | 3.27k | } else { |
316 | 0 | return _union.indirect_contents.capacity; |
317 | 0 | } |
318 | 3.27k | } _ZNK9prevectorILj28EhjiE8capacityEv Line | Count | Source | 312 | 3.27k | size_t capacity() const { | 313 | 3.27k | if (is_direct()) { | 314 | 3.27k | return N; | 315 | 3.27k | } else { | 316 | 0 | return _union.indirect_contents.capacity; | 317 | 0 | } | 318 | 3.27k | } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE8capacityEv Unexecuted instantiation: _ZNK9prevectorILj8EijiE8capacityEv Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8capacityEv Unexecuted instantiation: _ZNK9prevectorILj35EhjiE8capacityEv |
319 | | |
320 | 0 | T& operator[](size_type pos) { |
321 | 0 | return *item_ptr(pos); |
322 | 0 | } Unexecuted instantiation: _ZN9prevectorILj28EhjiEixEj Unexecuted instantiation: _ZN9prevectorILj8EijiEixEj Unexecuted instantiation: _ZN9prevectorILj33EhjiEixEj Unexecuted instantiation: _ZN9prevectorILj16EhjiEixEj |
323 | | |
324 | 54 | const T& operator[](size_type pos) const { |
325 | 54 | return *item_ptr(pos); |
326 | 54 | } Unexecuted instantiation: _ZNK9prevectorILj16EhjiEixEj _ZNK9prevectorILj28EhjiEixEj Line | Count | Source | 324 | 54 | const T& operator[](size_type pos) const { | 325 | 54 | return *item_ptr(pos); | 326 | 54 | } |
Unexecuted instantiation: _ZNK9prevectorILj8EijiEixEj |
327 | | |
328 | 3.32M | void resize(size_type new_size) { |
329 | 3.32M | size_type cur_size = size(); |
330 | 3.32M | if (cur_size == new_size) { |
331 | 3.32M | return; |
332 | 3.32M | } |
333 | 0 | if (cur_size > new_size) { |
334 | 0 | erase(item_ptr(new_size), end()); |
335 | 0 | return; |
336 | 0 | } |
337 | 0 | if (new_size > capacity()) { |
338 | 0 | change_capacity(new_size); |
339 | 0 | } |
340 | 0 | ptrdiff_t increase = new_size - cur_size; |
341 | 0 | fill(item_ptr(cur_size), increase); |
342 | 0 | _size += increase; |
343 | 0 | } _ZN9prevectorILj28EhjiE6resizeEj Line | Count | Source | 328 | 3.32M | void resize(size_type new_size) { | 329 | 3.32M | size_type cur_size = size(); | 330 | 3.32M | if (cur_size == new_size) { | 331 | 3.32M | return; | 332 | 3.32M | } | 333 | 0 | if (cur_size > new_size) { | 334 | 0 | erase(item_ptr(new_size), end()); | 335 | 0 | return; | 336 | 0 | } | 337 | 0 | if (new_size > capacity()) { | 338 | 0 | change_capacity(new_size); | 339 | 0 | } | 340 | 0 | ptrdiff_t increase = new_size - cur_size; | 341 | 0 | fill(item_ptr(cur_size), increase); | 342 | 0 | _size += increase; | 343 | 0 | } |
Unexecuted instantiation: _ZN9prevectorILj16EhjiE6resizeEj Unexecuted instantiation: _ZN9prevectorILj8EijiE6resizeEj Unexecuted instantiation: _ZN9prevectorILj33EhjiE6resizeEj |
344 | | |
345 | 0 | void reserve(size_type new_capacity) { |
346 | 0 | if (new_capacity > capacity()) { |
347 | 0 | change_capacity(new_capacity); |
348 | 0 | } |
349 | 0 | } Unexecuted instantiation: _ZN9prevectorILj28EhjiE7reserveEj Unexecuted instantiation: _ZN9prevectorILj8EijiE7reserveEj |
350 | | |
351 | 3.32M | void shrink_to_fit() { |
352 | 3.32M | change_capacity(size()); |
353 | 3.32M | } _ZN9prevectorILj28EhjiE13shrink_to_fitEv Line | Count | Source | 351 | 3.32M | void shrink_to_fit() { | 352 | 3.32M | change_capacity(size()); | 353 | 3.32M | } |
Unexecuted instantiation: _ZN9prevectorILj8EijiE13shrink_to_fitEv |
354 | | |
355 | 3.32M | void clear() { |
356 | 3.32M | resize(0); |
357 | 3.32M | } _ZN9prevectorILj28EhjiE5clearEv Line | Count | Source | 355 | 3.32M | void clear() { | 356 | 3.32M | resize(0); | 357 | 3.32M | } |
Unexecuted instantiation: _ZN9prevectorILj16EhjiE5clearEv Unexecuted instantiation: _ZN9prevectorILj8EijiE5clearEv Unexecuted instantiation: _ZN9prevectorILj33EhjiE5clearEv |
358 | | |
359 | 924 | iterator insert(iterator pos, const T& value) { |
360 | 924 | size_type p = pos - begin(); |
361 | 924 | size_type new_size = size() + 1; |
362 | 924 | if (capacity() < new_size) { |
363 | 0 | change_capacity(new_size + (new_size >> 1)); |
364 | 0 | } |
365 | 924 | T* ptr = item_ptr(p); |
366 | 924 | T* dst = ptr + 1; |
367 | 924 | memmove(dst, ptr, (size() - p) * sizeof(T)); |
368 | 924 | _size++; |
369 | 924 | new(static_cast<void*>(ptr)) T(value); |
370 | 924 | return iterator(ptr); |
371 | 924 | } _ZN9prevectorILj28EhjiE6insertENS0_8iteratorERKh Line | Count | Source | 359 | 924 | iterator insert(iterator pos, const T& value) { | 360 | 924 | size_type p = pos - begin(); | 361 | 924 | size_type new_size = size() + 1; | 362 | 924 | if (capacity() < new_size) { | 363 | 0 | change_capacity(new_size + (new_size >> 1)); | 364 | 0 | } | 365 | 924 | T* ptr = item_ptr(p); | 366 | 924 | T* dst = ptr + 1; | 367 | 924 | memmove(dst, ptr, (size() - p) * sizeof(T)); | 368 | 924 | _size++; | 369 | 924 | new(static_cast<void*>(ptr)) T(value); | 370 | 924 | return iterator(ptr); | 371 | 924 | } |
Unexecuted instantiation: _ZN9prevectorILj8EijiE6insertENS0_8iteratorERKi |
372 | | |
373 | 0 | void insert(iterator pos, size_type count, const T& value) { |
374 | 0 | size_type p = pos - begin(); |
375 | 0 | size_type new_size = size() + count; |
376 | 0 | if (capacity() < new_size) { |
377 | 0 | change_capacity(new_size + (new_size >> 1)); |
378 | 0 | } |
379 | 0 | T* ptr = item_ptr(p); |
380 | 0 | T* dst = ptr + count; |
381 | 0 | memmove(dst, ptr, (size() - p) * sizeof(T)); |
382 | 0 | _size += count; |
383 | 0 | fill(item_ptr(p), count, value); |
384 | 0 | } Unexecuted instantiation: _ZN9prevectorILj8EijiE6insertENS0_8iteratorEjRKi Unexecuted instantiation: _ZN9prevectorILj28EhjiE6insertENS0_8iteratorEjRKh |
385 | | |
386 | | template <std::input_iterator InputIterator> |
387 | 1.50k | void insert(iterator pos, InputIterator first, InputIterator last) { |
388 | 1.50k | size_type p = pos - begin(); |
389 | 1.50k | difference_type count = last - first; |
390 | 1.50k | size_type new_size = size() + count; |
391 | 1.50k | if (capacity() < new_size) { |
392 | 731 | change_capacity(new_size + (new_size >> 1)); |
393 | 731 | } |
394 | 1.50k | T* ptr = item_ptr(p); |
395 | 1.50k | T* dst = ptr + count; |
396 | 1.50k | memmove(dst, ptr, (size() - p) * sizeof(T)); |
397 | 1.50k | _size += count; |
398 | 1.50k | fill(ptr, first, last); |
399 | 1.50k | } _ZN9prevectorILj28EhjiE6insertITkSt14input_iteratorPKhEEvNS0_8iteratorET_S5_ Line | Count | Source | 387 | 650 | void insert(iterator pos, InputIterator first, InputIterator last) { | 388 | 650 | size_type p = pos - begin(); | 389 | 650 | difference_type count = last - first; | 390 | 650 | size_type new_size = size() + count; | 391 | 650 | if (capacity() < new_size) { | 392 | 0 | change_capacity(new_size + (new_size >> 1)); | 393 | 0 | } | 394 | 650 | T* ptr = item_ptr(p); | 395 | 650 | T* dst = ptr + count; | 396 | 650 | memmove(dst, ptr, (size() - p) * sizeof(T)); | 397 | 650 | _size += count; | 398 | 650 | fill(ptr, first, last); | 399 | 650 | } |
_ZN9prevectorILj28EhjiE6insertITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPKhSt4spanIS4_Lm18446744073709551615EEEEEEvNS0_8iteratorET_SA_ Line | Count | Source | 387 | 850 | void insert(iterator pos, InputIterator first, InputIterator last) { | 388 | 850 | size_type p = pos - begin(); | 389 | 850 | difference_type count = last - first; | 390 | 850 | size_type new_size = size() + count; | 391 | 850 | if (capacity() < new_size) { | 392 | 731 | change_capacity(new_size + (new_size >> 1)); | 393 | 731 | } | 394 | 850 | T* ptr = item_ptr(p); | 395 | 850 | T* dst = ptr + count; | 396 | 850 | memmove(dst, ptr, (size() - p) * sizeof(T)); | 397 | 850 | _size += count; | 398 | 850 | fill(ptr, first, last); | 399 | 850 | } |
Unexecuted instantiation: _ZN9prevectorILj28EhjiE6insertITkSt14input_iteratorNS0_8iteratorEEEvS2_T_S3_ Unexecuted instantiation: _ZN9prevectorILj8EijiE6insertITkSt14input_iteratorPiEEvNS0_8iteratorET_S4_ Unexecuted instantiation: _ZN9prevectorILj28EhjiE6insertITkSt14input_iteratorN9__gnu_cxx17__normal_iteratorIPhSt6vectorIhSaIhEEEEEEvNS0_8iteratorET_SA_ Unexecuted instantiation: _ZN9prevectorILj35EhjiE6insertITkSt14input_iteratorPhEEvNS0_8iteratorET_S4_ Unexecuted instantiation: _ZN9prevectorILj35EhjiE6insertITkSt14input_iteratorPKhEEvNS0_8iteratorET_S5_ Unexecuted instantiation: _ZN9prevectorILj28EhjiE6insertITkSt14input_iteratorNS0_14const_iteratorEEEvNS0_8iteratorET_S4_ |
400 | | |
401 | 0 | inline void resize_uninitialized(size_type new_size) { |
402 | | // resize_uninitialized changes the size of the prevector but does not initialize it. |
403 | | // If size < new_size, the added elements must be initialized explicitly. |
404 | 0 | if (capacity() < new_size) { |
405 | 0 | change_capacity(new_size); |
406 | 0 | _size += new_size - size(); |
407 | 0 | return; |
408 | 0 | } |
409 | 0 | if (new_size < size()) { |
410 | 0 | erase(item_ptr(new_size), end()); |
411 | 0 | } else { |
412 | 0 | _size += new_size - size(); |
413 | 0 | } |
414 | 0 | } Unexecuted instantiation: _ZN9prevectorILj28EhjiE20resize_uninitializedEj Unexecuted instantiation: _ZN9prevectorILj8EijiE20resize_uninitializedEj |
415 | | |
416 | 0 | iterator erase(iterator pos) { |
417 | 0 | return erase(pos, pos + 1); |
418 | 0 | } Unexecuted instantiation: _ZN9prevectorILj8EijiE5eraseENS0_8iteratorE Unexecuted instantiation: _ZN9prevectorILj33EhjiE5eraseENS0_8iteratorE |
419 | | |
420 | 0 | iterator erase(iterator first, iterator last) { |
421 | | // Erase is not allowed to the change the object's capacity. That means |
422 | | // that when starting with an indirectly allocated prevector with |
423 | | // size and capacity > N, the result may be a still indirectly allocated |
424 | | // prevector with size <= N and capacity > N. A shrink_to_fit() call is |
425 | | // necessary to switch to the (more efficient) directly allocated |
426 | | // representation (with capacity N and size <= N). |
427 | 0 | iterator p = first; |
428 | 0 | char* endp = (char*)&(*end()); |
429 | 0 | _size -= last - p; |
430 | 0 | memmove(&(*first), &(*last), endp - ((char*)(&(*last)))); |
431 | 0 | return first; |
432 | 0 | } Unexecuted instantiation: _ZN9prevectorILj28EhjiE5eraseENS0_8iteratorES1_ Unexecuted instantiation: _ZN9prevectorILj16EhjiE5eraseENS0_8iteratorES1_ Unexecuted instantiation: _ZN9prevectorILj8EijiE5eraseENS0_8iteratorES1_ Unexecuted instantiation: _ZN9prevectorILj33EhjiE5eraseENS0_8iteratorES1_ |
433 | | |
434 | | template<typename... Args> |
435 | 0 | void emplace_back(Args&&... args) { |
436 | 0 | size_type new_size = size() + 1; |
437 | 0 | if (capacity() < new_size) { |
438 | 0 | change_capacity(new_size + (new_size >> 1)); |
439 | 0 | } |
440 | 0 | new(item_ptr(size())) T(std::forward<Args>(args)...); |
441 | 0 | _size++; |
442 | 0 | } Unexecuted instantiation: _ZN9prevectorILj28EhjiE12emplace_backIJRKhEEEvDpOT_ Unexecuted instantiation: _ZN9prevectorILj8EijiE12emplace_backIJRKiEEEvDpOT_ |
443 | | |
444 | 0 | void push_back(const T& value) { |
445 | 0 | emplace_back(value); |
446 | 0 | } Unexecuted instantiation: _ZN9prevectorILj28EhjiE9push_backERKh Unexecuted instantiation: _ZN9prevectorILj8EijiE9push_backERKi |
447 | | |
448 | 0 | void pop_back() { |
449 | 0 | erase(end() - 1, end()); |
450 | 0 | } |
451 | | |
452 | | T& front() { |
453 | | return *item_ptr(0); |
454 | | } |
455 | | |
456 | | const T& front() const { |
457 | | return *item_ptr(0); |
458 | | } |
459 | | |
460 | 0 | T& back() { |
461 | 0 | return *item_ptr(size() - 1); |
462 | 0 | } |
463 | | |
464 | 0 | const T& back() const { |
465 | 0 | return *item_ptr(size() - 1); |
466 | 0 | } |
467 | | |
468 | | void swap(prevector<N, T, Size, Diff>& other) noexcept |
469 | 0 | { |
470 | 0 | std::swap(_union, other._union); |
471 | 0 | std::swap(_size, other._size); |
472 | 0 | } |
473 | | |
474 | 6.38M | ~prevector() { |
475 | 6.38M | if (!is_direct()) { |
476 | 2.92k | free(_union.indirect_contents.indirect); |
477 | 2.92k | _union.indirect_contents.indirect = nullptr; |
478 | 2.92k | } |
479 | 6.38M | } Unexecuted instantiation: _ZN9prevectorILj16EhjiED2Ev _ZN9prevectorILj28EhjiED2Ev Line | Count | Source | 474 | 6.38M | ~prevector() { | 475 | 6.38M | if (!is_direct()) { | 476 | 2.92k | free(_union.indirect_contents.indirect); | 477 | 2.92k | _union.indirect_contents.indirect = nullptr; | 478 | 2.92k | } | 479 | 6.38M | } |
Unexecuted instantiation: _ZN9prevectorILj33EhjiED2Ev Unexecuted instantiation: _ZN9prevectorILj8EijiED2Ev Unexecuted instantiation: _ZN9prevectorILj35EhjiED2Ev |
480 | | |
481 | 0 | bool operator==(const prevector<N, T, Size, Diff>& other) const { |
482 | 0 | if (other.size() != size()) { |
483 | 0 | return false; |
484 | 0 | } |
485 | 0 | const_iterator b1 = begin(); |
486 | 0 | const_iterator b2 = other.begin(); |
487 | 0 | const_iterator e1 = end(); |
488 | 0 | while (b1 != e1) { |
489 | 0 | if ((*b1) != (*b2)) { |
490 | 0 | return false; |
491 | 0 | } |
492 | 0 | ++b1; |
493 | 0 | ++b2; |
494 | 0 | } |
495 | 0 | return true; |
496 | 0 | } Unexecuted instantiation: _ZNK9prevectorILj28EhjiEeqERKS0_ Unexecuted instantiation: _ZNK9prevectorILj8EijiEeqERKS0_ Unexecuted instantiation: _ZNK9prevectorILj16EhjiEeqERKS0_ |
497 | | |
498 | 0 | bool operator!=(const prevector<N, T, Size, Diff>& other) const { |
499 | 0 | return !(*this == other); |
500 | 0 | } |
501 | | |
502 | 0 | bool operator<(const prevector<N, T, Size, Diff>& other) const { |
503 | 0 | if (size() < other.size()) { |
504 | 0 | return true; |
505 | 0 | } |
506 | 0 | if (size() > other.size()) { |
507 | 0 | return false; |
508 | 0 | } |
509 | 0 | const_iterator b1 = begin(); |
510 | 0 | const_iterator b2 = other.begin(); |
511 | 0 | const_iterator e1 = end(); |
512 | 0 | while (b1 != e1) { |
513 | 0 | if ((*b1) < (*b2)) { |
514 | 0 | return true; |
515 | 0 | } |
516 | 0 | if ((*b2) < (*b1)) { |
517 | 0 | return false; |
518 | 0 | } |
519 | 0 | ++b1; |
520 | 0 | ++b2; |
521 | 0 | } |
522 | 0 | return false; |
523 | 0 | } Unexecuted instantiation: _ZNK9prevectorILj28EhjiEltERKS0_ Unexecuted instantiation: _ZNK9prevectorILj16EhjiEltERKS0_ |
524 | | |
525 | 0 | size_t allocated_memory() const { |
526 | 0 | if (is_direct()) { |
527 | 0 | return 0; |
528 | 0 | } else { |
529 | 0 | return ((size_t)(sizeof(T))) * _union.indirect_contents.capacity; |
530 | 0 | } |
531 | 0 | } |
532 | | |
533 | 0 | value_type* data() { |
534 | 0 | return item_ptr(0); |
535 | 0 | } Unexecuted instantiation: _ZN9prevectorILj33EhjiE4dataEv Unexecuted instantiation: _ZN9prevectorILj28EhjiE4dataEv Unexecuted instantiation: _ZN9prevectorILj16EhjiE4dataEv Unexecuted instantiation: _ZN9prevectorILj35EhjiE4dataEv |
536 | | |
537 | 849 | const value_type* data() const { |
538 | 849 | return item_ptr(0); |
539 | 849 | } _ZNK9prevectorILj28EhjiE4dataEv Line | Count | Source | 537 | 849 | const value_type* data() const { | 538 | 849 | return item_ptr(0); | 539 | 849 | } |
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE4dataEv Unexecuted instantiation: _ZNK9prevectorILj33EhjiE4dataEv |
540 | | }; |
541 | | |
542 | | #endif // BITCOIN_PREVECTOR_H |