/Users/brunogarcia/projects/bitcoin-core-dev/src/prevector.h
Line | Count | Source |
1 | | // Copyright (c) 2015-present 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 | | static constexpr unsigned int STATIC_SIZE{N}; |
42 | | |
43 | | typedef Size size_type; |
44 | | typedef Diff difference_type; |
45 | | typedef T value_type; |
46 | | typedef value_type& reference; |
47 | | typedef const value_type& const_reference; |
48 | | typedef value_type* pointer; |
49 | | typedef const value_type* const_pointer; |
50 | | |
51 | | class iterator { |
52 | | T* ptr{}; |
53 | | public: |
54 | | typedef Diff difference_type; |
55 | | typedef T* pointer; |
56 | | typedef T& reference; |
57 | | using element_type = T; |
58 | | using iterator_category = std::contiguous_iterator_tag; |
59 | | iterator() = default; |
60 | 1.45M | iterator(T* ptr_) : ptr(ptr_) {}Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::iterator::iterator(unsigned char*) prevector<36u, unsigned char, unsigned int, int>::iterator::iterator(unsigned char*) Line | Count | Source | 60 | 1.45M | iterator(T* ptr_) : ptr(ptr_) {} |
Unexecuted instantiation: prevector<8u, int, unsigned int, int>::iterator::iterator(int*) Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::iterator::iterator(unsigned char*) Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::iterator::iterator(unsigned char*) |
61 | 1.06M | T& operator*() const { return *ptr; }prevector<36u, unsigned char, unsigned int, int>::iterator::operator*() const Line | Count | Source | 61 | 1.06M | T& operator*() const { return *ptr; } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::iterator::operator*() const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::iterator::operator*() const Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::iterator::operator*() const Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::iterator::operator*() const |
62 | 0 | T* operator->() const { return ptr; } |
63 | | T& operator[](size_type pos) const { return ptr[pos]; } |
64 | 0 | iterator& operator++() { ptr++; return *this; } |
65 | | iterator& operator--() { ptr--; return *this; } |
66 | | iterator operator++(int) { iterator copy(*this); ++(*this); return copy; } |
67 | | iterator operator--(int) { iterator copy(*this); --(*this); return copy; } |
68 | 530k | difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }operator-(prevector<36u, unsigned char, unsigned int, int>::iterator, prevector<36u, unsigned char, unsigned int, int>::iterator) Line | Count | Source | 68 | 530k | difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); } |
Unexecuted instantiation: operator-(prevector<16u, unsigned char, unsigned int, int>::iterator, prevector<16u, unsigned char, unsigned int, int>::iterator) Unexecuted instantiation: operator-(prevector<8u, int, unsigned int, int>::iterator, prevector<8u, int, unsigned int, int>::iterator) Unexecuted instantiation: operator-(prevector<33u, unsigned char, unsigned int, int>::iterator, prevector<33u, unsigned char, unsigned int, int>::iterator) Unexecuted instantiation: operator-(prevector<35u, unsigned char, unsigned int, int>::iterator, prevector<35u, unsigned char, unsigned int, int>::iterator) |
69 | 0 | iterator operator+(size_type n) const { return iterator(ptr + n); }Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::iterator::operator+(unsigned int) const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::iterator::operator+(unsigned int) const Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::iterator::operator+(unsigned int) const |
70 | | iterator friend operator+(size_type n, iterator x) { return x + n; } |
71 | | iterator& operator+=(size_type n) { ptr += n; return *this; } |
72 | 0 | iterator operator-(size_type n) const { return iterator(ptr - n); } |
73 | | iterator& operator-=(size_type n) { ptr -= n; return *this; } |
74 | | bool operator==(iterator x) const { return ptr == x.ptr; } |
75 | 0 | 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 | | bool operator>(iterator x) const { return ptr > x.ptr; } |
79 | | bool operator<(iterator x) const { return ptr < x.ptr; } |
80 | | }; |
81 | | |
82 | | class const_iterator { |
83 | | const T* ptr{}; |
84 | | public: |
85 | | typedef Diff difference_type; |
86 | | typedef const T* pointer; |
87 | | typedef const T& reference; |
88 | | using element_type = const T; |
89 | | using iterator_category = std::contiguous_iterator_tag; |
90 | | const_iterator() = default; |
91 | 2.58M | const_iterator(const T* ptr_) : ptr(ptr_) {}Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::const_iterator::const_iterator(unsigned char const*) prevector<36u, unsigned char, unsigned int, int>::const_iterator::const_iterator(unsigned char const*) Line | Count | Source | 91 | 2.58M | const_iterator(const T* ptr_) : ptr(ptr_) {} |
Unexecuted instantiation: prevector<8u, int, unsigned int, int>::const_iterator::const_iterator(int const*) |
92 | 0 | const_iterator(iterator x) : ptr(&(*x)) {} |
93 | 23.8M | const T& operator*() const { return *ptr; }prevector<36u, unsigned char, unsigned int, int>::const_iterator::operator*() const Line | Count | Source | 93 | 23.8M | const T& operator*() const { return *ptr; } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::const_iterator::operator*() const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::const_iterator::operator*() const |
94 | 27.2k | const T* operator->() const { return ptr; }Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::const_iterator::operator->() const prevector<36u, unsigned char, unsigned int, int>::const_iterator::operator->() const Line | Count | Source | 94 | 27.2k | const T* operator->() const { return ptr; } |
|
95 | 0 | const T& operator[](size_type pos) const { return ptr[pos]; }Unexecuted instantiation: prevector<8u, int, unsigned int, int>::const_iterator::operator[](unsigned int) const Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::const_iterator::operator[](unsigned int) const |
96 | 21.3M | const_iterator& operator++() { ptr++; return *this; }prevector<36u, unsigned char, unsigned int, int>::const_iterator::operator++() Line | Count | Source | 96 | 21.3M | const_iterator& operator++() { ptr++; return *this; } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::const_iterator::operator++() Unexecuted instantiation: prevector<8u, int, unsigned int, int>::const_iterator::operator++() |
97 | 0 | const_iterator& operator--() { ptr--; return *this; } |
98 | 0 | const_iterator operator++(int) { const_iterator copy(*this); ++(*this); return copy; } |
99 | | const_iterator operator--(int) { const_iterator copy(*this); --(*this); return copy; } |
100 | 13.6k | difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); }Unexecuted instantiation: operator-(prevector<16u, unsigned char, unsigned int, int>::const_iterator, prevector<16u, unsigned char, unsigned int, int>::const_iterator) operator-(prevector<36u, unsigned char, unsigned int, int>::const_iterator, prevector<36u, unsigned char, unsigned int, int>::const_iterator) Line | Count | Source | 100 | 13.6k | difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); } |
Unexecuted instantiation: operator-(prevector<8u, int, unsigned int, int>::const_iterator, prevector<8u, int, unsigned int, int>::const_iterator) |
101 | 21.8k | const_iterator operator+(size_type n) const { return const_iterator(ptr + n); }Unexecuted instantiation: prevector<8u, int, unsigned int, int>::const_iterator::operator+(unsigned int) const prevector<36u, unsigned char, unsigned int, int>::const_iterator::operator+(unsigned int) const Line | Count | Source | 101 | 21.8k | const_iterator operator+(size_type n) const { return const_iterator(ptr + n); } |
|
102 | | const_iterator friend operator+(size_type n, const_iterator x) { return x + n; } |
103 | 0 | const_iterator& operator+=(size_type n) { ptr += n; return *this; } |
104 | 0 | const_iterator operator-(size_type n) const { return const_iterator(ptr - n); }Unexecuted instantiation: prevector<8u, int, unsigned int, int>::const_iterator::operator-(unsigned int) const Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::const_iterator::operator-(unsigned int) const |
105 | | const_iterator& operator-=(size_type n) { ptr -= n; return *this; } |
106 | 0 | bool operator==(const_iterator x) const { return ptr == x.ptr; } |
107 | 20.4M | bool operator!=(const_iterator x) const { return ptr != x.ptr; }prevector<36u, unsigned char, unsigned int, int>::const_iterator::operator!=(prevector<36u, unsigned char, unsigned int, int>::const_iterator) const Line | Count | Source | 107 | 20.4M | bool operator!=(const_iterator x) const { return ptr != x.ptr; } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::const_iterator::operator!=(prevector<16u, unsigned char, unsigned int, int>::const_iterator) const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::const_iterator::operator!=(prevector<8u, int, unsigned int, int>::const_iterator) const |
108 | 0 | bool operator>=(const_iterator x) const { return ptr >= x.ptr; } |
109 | | bool operator<=(const_iterator x) const { return ptr <= x.ptr; } |
110 | | bool operator>(const_iterator x) const { return ptr > x.ptr; } |
111 | 0 | bool operator<(const_iterator x) const { return ptr < x.ptr; } |
112 | | }; |
113 | | |
114 | | private: |
115 | | #pragma pack(push, 1) |
116 | | union direct_or_indirect { |
117 | | char direct[sizeof(T) * N]; |
118 | | struct { |
119 | | char* indirect; |
120 | | size_type capacity; |
121 | | } indirect_contents; |
122 | | }; |
123 | | #pragma pack(pop) |
124 | | alignas(char*) direct_or_indirect _union = {}; |
125 | | size_type _size = 0; |
126 | | |
127 | | static_assert(alignof(char*) % alignof(size_type) == 0 && sizeof(char*) % alignof(size_type) == 0, "size_type cannot have more restrictive alignment requirement than pointer"); |
128 | | static_assert(alignof(char*) % alignof(T) == 0, "value_type T cannot have more restrictive alignment requirement than pointer"); |
129 | | |
130 | 2.73M | T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }prevector<36u, unsigned char, unsigned int, int>::direct_ptr(int) Line | Count | Source | 130 | 2.73M | T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; } |
Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::direct_ptr(int) Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::direct_ptr(int) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::direct_ptr(int) Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::direct_ptr(int) |
131 | 2.80M | const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; }prevector<36u, unsigned char, unsigned int, int>::direct_ptr(int) const Line | Count | Source | 131 | 2.80M | const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::direct_ptr(int) const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::direct_ptr(int) const Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::direct_ptr(int) const |
132 | 50.1k | T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; }prevector<36u, unsigned char, unsigned int, int>::indirect_ptr(int) Line | Count | Source | 132 | 50.1k | T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; } |
Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::indirect_ptr(int) Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::indirect_ptr(int) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::indirect_ptr(int) Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::indirect_ptr(int) |
133 | 110k | const T* indirect_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.indirect_contents.indirect) + pos; }prevector<36u, unsigned char, unsigned int, int>::indirect_ptr(int) const Line | Count | Source | 133 | 110k | const T* indirect_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.indirect_contents.indirect) + pos; } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::indirect_ptr(int) const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::indirect_ptr(int) const Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::indirect_ptr(int) const |
134 | 15.1M | bool is_direct() const { return _size <= N; }prevector<36u, unsigned char, unsigned int, int>::is_direct() const Line | Count | Source | 134 | 15.1M | bool is_direct() const { return _size <= N; } |
Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::is_direct() const Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::is_direct() const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::is_direct() const Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::is_direct() const |
135 | | |
136 | 1.16M | void change_capacity(size_type new_capacity) { |
137 | 1.16M | if (new_capacity <= N) { |
138 | 1.11M | if (!is_direct()) { |
139 | 0 | T* indirect = indirect_ptr(0); |
140 | 0 | T* src = indirect; |
141 | 0 | T* dst = direct_ptr(0); |
142 | 0 | memcpy(dst, src, size() * sizeof(T)); |
143 | 0 | free(indirect); |
144 | 0 | _size -= N + 1; |
145 | 0 | } |
146 | 1.11M | } else { |
147 | 50.1k | if (!is_direct()) { |
148 | | /* FIXME: Because malloc/realloc here won't call new_handler if allocation fails, assert |
149 | | success. These should instead use an allocator or new/delete so that handlers |
150 | | are called as necessary, but performance would be slightly degraded by doing so. */ |
151 | 0 | _union.indirect_contents.indirect = static_cast<char*>(realloc(_union.indirect_contents.indirect, ((size_t)sizeof(T)) * new_capacity)); |
152 | 0 | assert(_union.indirect_contents.indirect); |
153 | 0 | _union.indirect_contents.capacity = new_capacity; |
154 | 50.1k | } else { |
155 | 50.1k | char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity)); |
156 | 50.1k | assert(new_indirect); |
157 | 50.1k | T* src = direct_ptr(0); |
158 | 50.1k | T* dst = reinterpret_cast<T*>(new_indirect); |
159 | 50.1k | memcpy(dst, src, size() * sizeof(T)); |
160 | 50.1k | _union.indirect_contents.indirect = new_indirect; |
161 | 50.1k | _union.indirect_contents.capacity = new_capacity; |
162 | 50.1k | _size += N + 1; |
163 | 50.1k | } |
164 | 50.1k | } |
165 | 1.16M | } prevector<36u, unsigned char, unsigned int, int>::change_capacity(unsigned int) Line | Count | Source | 136 | 1.16M | void change_capacity(size_type new_capacity) { | 137 | 1.16M | if (new_capacity <= N) { | 138 | 1.11M | if (!is_direct()) { | 139 | 0 | T* indirect = indirect_ptr(0); | 140 | 0 | T* src = indirect; | 141 | 0 | T* dst = direct_ptr(0); | 142 | 0 | memcpy(dst, src, size() * sizeof(T)); | 143 | 0 | free(indirect); | 144 | 0 | _size -= N + 1; | 145 | 0 | } | 146 | 1.11M | } else { | 147 | 50.1k | if (!is_direct()) { | 148 | | /* FIXME: Because malloc/realloc here won't call new_handler if allocation fails, assert | 149 | | success. These should instead use an allocator or new/delete so that handlers | 150 | | are called as necessary, but performance would be slightly degraded by doing so. */ | 151 | 0 | _union.indirect_contents.indirect = static_cast<char*>(realloc(_union.indirect_contents.indirect, ((size_t)sizeof(T)) * new_capacity)); | 152 | 0 | assert(_union.indirect_contents.indirect); | 153 | 0 | _union.indirect_contents.capacity = new_capacity; | 154 | 50.1k | } else { | 155 | 50.1k | char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity)); | 156 | 50.1k | assert(new_indirect); | 157 | 50.1k | T* src = direct_ptr(0); | 158 | 50.1k | T* dst = reinterpret_cast<T*>(new_indirect); | 159 | 50.1k | memcpy(dst, src, size() * sizeof(T)); | 160 | 50.1k | _union.indirect_contents.indirect = new_indirect; | 161 | 50.1k | _union.indirect_contents.capacity = new_capacity; | 162 | 50.1k | _size += N + 1; | 163 | 50.1k | } | 164 | 50.1k | } | 165 | 1.16M | } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::change_capacity(unsigned int) Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::change_capacity(unsigned int) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::change_capacity(unsigned int) Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::change_capacity(unsigned int) |
166 | | |
167 | 2.73M | T* item_ptr(difference_type pos) { return is_direct() ? direct_ptr(pos)2.68M : indirect_ptr(pos)50.1k ; }prevector<36u, unsigned char, unsigned int, int>::item_ptr(int) Line | Count | Source | 167 | 2.73M | T* item_ptr(difference_type pos) { return is_direct() ? direct_ptr(pos)2.68M : indirect_ptr(pos)50.1k ; } |
Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::item_ptr(int) Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::item_ptr(int) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::item_ptr(int) Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::item_ptr(int) |
168 | 2.91M | const T* item_ptr(difference_type pos) const { return is_direct() ? direct_ptr(pos)2.80M : indirect_ptr(pos)110k ; }prevector<36u, unsigned char, unsigned int, int>::item_ptr(int) const Line | Count | Source | 168 | 2.91M | const T* item_ptr(difference_type pos) const { return is_direct() ? direct_ptr(pos)2.80M : indirect_ptr(pos)110k ; } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::item_ptr(int) const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::item_ptr(int) const Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::item_ptr(int) const |
169 | | |
170 | 0 | void fill(T* dst, ptrdiff_t count, const T& value = T{}) { |
171 | 0 | std::fill_n(dst, count, value); |
172 | 0 | } Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::fill(unsigned char*, long, unsigned char const&) Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::fill(unsigned char*, long, unsigned char const&) Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::fill(unsigned char*, long, unsigned char const&) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::fill(int*, long, int const&) |
173 | | |
174 | | template <std::input_iterator InputIterator> |
175 | 1.26M | void fill(T* dst, InputIterator first, InputIterator last) { |
176 | 21.4M | while (first != last) { |
177 | 20.2M | new(static_cast<void*>(dst)) T(*first); |
178 | 20.2M | ++dst; |
179 | 20.2M | ++first; |
180 | 20.2M | } |
181 | 1.26M | } Unexecuted instantiation: void prevector<36u, unsigned char, unsigned int, int>::fill<unsigned char const*>(unsigned char*, unsigned char const*, unsigned char const*) void prevector<36u, unsigned char, unsigned int, int>::fill<std::__1::__wrap_iter<unsigned char const*>>(unsigned char*, std::__1::__wrap_iter<unsigned char const*>, std::__1::__wrap_iter<unsigned char const*>) Line | Count | Source | 175 | 138k | void fill(T* dst, InputIterator first, InputIterator last) { | 176 | 3.28M | while (first != last) { | 177 | 3.14M | new(static_cast<void*>(dst)) T(*first); | 178 | 3.14M | ++dst; | 179 | 3.14M | ++first; | 180 | 3.14M | } | 181 | 138k | } |
void prevector<36u, unsigned char, unsigned int, int>::fill<prevector<36u, unsigned char, unsigned int, int>::const_iterator>(unsigned char*, prevector<36u, unsigned char, unsigned int, int>::const_iterator, prevector<36u, unsigned char, unsigned int, int>::const_iterator) Line | Count | Source | 175 | 1.12M | void fill(T* dst, InputIterator first, InputIterator last) { | 176 | 18.2M | while (first != last) { | 177 | 17.0M | new(static_cast<void*>(dst)) T(*first); | 178 | 17.0M | ++dst; | 179 | 17.0M | ++first; | 180 | 17.0M | } | 181 | 1.12M | } |
Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::fill<prevector<16u, unsigned char, unsigned int, int>::const_iterator>(unsigned char*, prevector<16u, unsigned char, unsigned int, int>::const_iterator, prevector<16u, unsigned char, unsigned int, int>::const_iterator) Unexecuted instantiation: void prevector<36u, unsigned char, unsigned int, int>::fill<prevector<36u, unsigned char, unsigned int, int>::iterator>(unsigned char*, prevector<36u, unsigned char, unsigned int, int>::iterator, prevector<36u, unsigned char, unsigned int, int>::iterator) Unexecuted instantiation: void prevector<8u, int, unsigned int, int>::fill<int*>(int*, int*, int*) Unexecuted instantiation: void prevector<8u, int, unsigned int, int>::fill<prevector<8u, int, unsigned int, int>::const_iterator>(int*, prevector<8u, int, unsigned int, int>::const_iterator, prevector<8u, int, unsigned int, int>::const_iterator) Unexecuted instantiation: void prevector<8u, int, unsigned int, int>::fill<std::__1::__wrap_iter<int const*>>(int*, std::__1::__wrap_iter<int const*>, std::__1::__wrap_iter<int const*>) Unexecuted instantiation: void prevector<33u, unsigned char, unsigned int, int>::fill<std::__1::__wrap_iter<unsigned char const*>>(unsigned char*, std::__1::__wrap_iter<unsigned char const*>, std::__1::__wrap_iter<unsigned char const*>) Unexecuted instantiation: void prevector<36u, unsigned char, unsigned int, int>::fill<std::__1::__wrap_iter<unsigned char*>>(unsigned char*, std::__1::__wrap_iter<unsigned char*>, std::__1::__wrap_iter<unsigned char*>) Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::fill<std::__1::__wrap_iter<unsigned char const*>>(unsigned char*, std::__1::__wrap_iter<unsigned char const*>, std::__1::__wrap_iter<unsigned char const*>) Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::fill<unsigned char*>(unsigned char*, unsigned char*, unsigned char*) Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::fill<std::__1::__wrap_iter<unsigned char*>>(unsigned char*, std::__1::__wrap_iter<unsigned char*>, std::__1::__wrap_iter<unsigned char*>) Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::fill<unsigned char const*>(unsigned char*, unsigned char const*, unsigned char const*) Unexecuted instantiation: void prevector<35u, unsigned char, unsigned int, int>::fill<std::__1::__wrap_iter<unsigned char const*>>(unsigned char*, std::__1::__wrap_iter<unsigned char const*>, std::__1::__wrap_iter<unsigned char const*>) Unexecuted instantiation: void prevector<35u, unsigned char, unsigned int, int>::fill<unsigned char*>(unsigned char*, unsigned char*, unsigned char*) Unexecuted instantiation: void prevector<35u, unsigned char, unsigned int, int>::fill<unsigned char const*>(unsigned char*, unsigned char const*, unsigned char const*) |
182 | | |
183 | | public: |
184 | 0 | void assign(size_type n, const T& val) { |
185 | 0 | clear(); |
186 | 0 | if (capacity() < n) { |
187 | 0 | change_capacity(n); |
188 | 0 | } |
189 | 0 | _size += n; |
190 | 0 | fill(item_ptr(0), n, val); |
191 | 0 | } Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::assign(unsigned int, unsigned char const&) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::assign(unsigned int, int const&) |
192 | | |
193 | | template <std::input_iterator InputIterator> |
194 | 0 | void assign(InputIterator first, InputIterator last) { |
195 | 0 | size_type n = last - first; |
196 | 0 | clear(); |
197 | 0 | if (capacity() < n) { |
198 | 0 | change_capacity(n); |
199 | 0 | } |
200 | 0 | _size += n; |
201 | 0 | fill(item_ptr(0), first, last); |
202 | 0 | } Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::assign<prevector<16u, unsigned char, unsigned int, int>::const_iterator>(prevector<16u, unsigned char, unsigned int, int>::const_iterator, prevector<16u, unsigned char, unsigned int, int>::const_iterator) Unexecuted instantiation: void prevector<36u, unsigned char, unsigned int, int>::assign<prevector<36u, unsigned char, unsigned int, int>::const_iterator>(prevector<36u, unsigned char, unsigned int, int>::const_iterator, prevector<36u, unsigned char, unsigned int, int>::const_iterator) Unexecuted instantiation: void prevector<8u, int, unsigned int, int>::assign<prevector<8u, int, unsigned int, int>::const_iterator>(prevector<8u, int, unsigned int, int>::const_iterator, prevector<8u, int, unsigned int, int>::const_iterator) Unexecuted instantiation: void prevector<33u, unsigned char, unsigned int, int>::assign<std::__1::__wrap_iter<unsigned char const*>>(std::__1::__wrap_iter<unsigned char const*>, std::__1::__wrap_iter<unsigned char const*>) Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::assign<std::__1::__wrap_iter<unsigned char const*>>(std::__1::__wrap_iter<unsigned char const*>, std::__1::__wrap_iter<unsigned char const*>) Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::assign<unsigned char*>(unsigned char*, unsigned char*) Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::assign<std::__1::__wrap_iter<unsigned char*>>(std::__1::__wrap_iter<unsigned char*>, std::__1::__wrap_iter<unsigned char*>) Unexecuted instantiation: void prevector<16u, unsigned char, unsigned int, int>::assign<unsigned char const*>(unsigned char const*, unsigned char const*) |
203 | | |
204 | 477k | prevector() = default; prevector<36u, unsigned char, unsigned int, int>::prevector() Line | Count | Source | 204 | 477k | prevector() = default; |
Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::prevector() Unexecuted instantiation: prevector<8u, int, unsigned int, int>::prevector() |
205 | | |
206 | | explicit prevector(size_type n) { |
207 | | resize(n); |
208 | | } |
209 | | |
210 | 0 | explicit prevector(size_type n, const T& val) { |
211 | 0 | change_capacity(n); |
212 | 0 | _size += n; |
213 | 0 | fill(item_ptr(0), n, val); |
214 | 0 | } Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::prevector(unsigned int, unsigned char const&) Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::prevector(unsigned int, unsigned char const&) |
215 | | |
216 | | template <std::input_iterator InputIterator> |
217 | 0 | prevector(InputIterator first, InputIterator last) { |
218 | 0 | size_type n = last - first; |
219 | 0 | change_capacity(n); |
220 | 0 | _size += n; |
221 | 0 | fill(item_ptr(0), first, last); |
222 | 0 | } Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::prevector<std::__1::__wrap_iter<unsigned char const*>>(std::__1::__wrap_iter<unsigned char const*>, std::__1::__wrap_iter<unsigned char const*>) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::prevector<std::__1::__wrap_iter<int const*>>(std::__1::__wrap_iter<int const*>, std::__1::__wrap_iter<int const*>) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::prevector<prevector<8u, int, unsigned int, int>::const_iterator>(prevector<8u, int, unsigned int, int>::const_iterator, prevector<8u, int, unsigned int, int>::const_iterator) Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::prevector<std::__1::__wrap_iter<unsigned char*>>(std::__1::__wrap_iter<unsigned char*>, std::__1::__wrap_iter<unsigned char*>) Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::prevector<std::__1::__wrap_iter<unsigned char const*>>(std::__1::__wrap_iter<unsigned char const*>, std::__1::__wrap_iter<unsigned char const*>) Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::prevector<prevector<36u, unsigned char, unsigned int, int>::const_iterator>(prevector<36u, unsigned char, unsigned int, int>::const_iterator, prevector<36u, unsigned char, unsigned int, int>::const_iterator) |
223 | | |
224 | 1.12M | prevector(const prevector<N, T, Size, Diff>& other) { |
225 | 1.12M | size_type n = other.size(); |
226 | 1.12M | change_capacity(n); |
227 | 1.12M | _size += n; |
228 | 1.12M | fill(item_ptr(0), other.begin(), other.end()); |
229 | 1.12M | } Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::prevector(prevector<16u, unsigned char, unsigned int, int> const&) prevector<36u, unsigned char, unsigned int, int>::prevector(prevector<36u, unsigned char, unsigned int, int> const&) Line | Count | Source | 224 | 1.12M | prevector(const prevector<N, T, Size, Diff>& other) { | 225 | 1.12M | size_type n = other.size(); | 226 | 1.12M | change_capacity(n); | 227 | 1.12M | _size += n; | 228 | 1.12M | fill(item_ptr(0), other.begin(), other.end()); | 229 | 1.12M | } |
|
230 | | |
231 | | prevector(prevector<N, T, Size, Diff>&& other) noexcept |
232 | 146k | : _union(std::move(other._union)), _size(other._size) |
233 | 146k | { |
234 | 146k | other._size = 0; |
235 | 146k | } Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::prevector(prevector<16u, unsigned char, unsigned int, int>&&) prevector<36u, unsigned char, unsigned int, int>::prevector(prevector<36u, unsigned char, unsigned int, int>&&) Line | Count | Source | 232 | 146k | : _union(std::move(other._union)), _size(other._size) | 233 | 146k | { | 234 | 146k | other._size = 0; | 235 | 146k | } |
|
236 | | |
237 | 0 | prevector& operator=(const prevector<N, T, Size, Diff>& other) { |
238 | 0 | if (&other == this) { |
239 | 0 | return *this; |
240 | 0 | } |
241 | 0 | assign(other.begin(), other.end()); |
242 | 0 | return *this; |
243 | 0 | } Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::operator=(prevector<16u, unsigned char, unsigned int, int> const&) Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::operator=(prevector<36u, unsigned char, unsigned int, int> const&) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::operator=(prevector<8u, int, unsigned int, int> const&) |
244 | | |
245 | 271k | prevector& operator=(prevector<N, T, Size, Diff>&& other) noexcept { |
246 | 271k | if (!is_direct()) { |
247 | 26.5k | free(_union.indirect_contents.indirect); |
248 | 26.5k | } |
249 | 271k | _union = std::move(other._union); |
250 | 271k | _size = other._size; |
251 | 271k | other._size = 0; |
252 | 271k | return *this; |
253 | 271k | } Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::operator=(prevector<16u, unsigned char, unsigned int, int>&&) prevector<36u, unsigned char, unsigned int, int>::operator=(prevector<36u, unsigned char, unsigned int, int>&&) Line | Count | Source | 245 | 271k | prevector& operator=(prevector<N, T, Size, Diff>&& other) noexcept { | 246 | 271k | if (!is_direct()) { | 247 | 26.5k | free(_union.indirect_contents.indirect); | 248 | 26.5k | } | 249 | 271k | _union = std::move(other._union); | 250 | 271k | _size = other._size; | 251 | 271k | other._size = 0; | 252 | 271k | return *this; | 253 | 271k | } |
Unexecuted instantiation: prevector<8u, int, unsigned int, int>::operator=(prevector<8u, int, unsigned int, int>&&) |
254 | | |
255 | 5.78M | size_type size() const { |
256 | 5.78M | return is_direct() ? _size5.63M : _size - N - 1152k ; |
257 | 5.78M | } prevector<36u, unsigned char, unsigned int, int>::size() const Line | Count | Source | 255 | 5.78M | size_type size() const { | 256 | 5.78M | return is_direct() ? _size5.63M : _size - N - 1152k ; | 257 | 5.78M | } |
Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::size() const Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::size() const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::size() const Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::size() const |
258 | | |
259 | 511k | bool empty() const { |
260 | 511k | return size() == 0; |
261 | 511k | } prevector<36u, unsigned char, unsigned int, int>::empty() const Line | Count | Source | 259 | 511k | bool empty() const { | 260 | 511k | return size() == 0; | 261 | 511k | } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::empty() const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::empty() const |
262 | | |
263 | 530k | iterator begin() { return iterator(item_ptr(0)); }Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::begin() prevector<36u, unsigned char, unsigned int, int>::begin() Line | Count | Source | 263 | 530k | iterator begin() { return iterator(item_ptr(0)); } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::begin() Unexecuted instantiation: prevector<8u, int, unsigned int, int>::begin() Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::begin() |
264 | 1.33M | const_iterator begin() const { return const_iterator(item_ptr(0)); }prevector<36u, unsigned char, unsigned int, int>::begin() const Line | Count | Source | 264 | 1.33M | const_iterator begin() const { return const_iterator(item_ptr(0)); } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::begin() const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::begin() const |
265 | 530k | iterator end() { return iterator(item_ptr(size())); }prevector<36u, unsigned char, unsigned int, int>::end() Line | Count | Source | 265 | 530k | iterator end() { return iterator(item_ptr(size())); } |
Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::end() Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::end() Unexecuted instantiation: prevector<8u, int, unsigned int, int>::end() Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::end() |
266 | 1.22M | const_iterator end() const { return const_iterator(item_ptr(size())); }prevector<36u, unsigned char, unsigned int, int>::end() const Line | Count | Source | 266 | 1.22M | const_iterator end() const { return const_iterator(item_ptr(size())); } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::end() const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::end() const |
267 | | |
268 | 546k | size_t capacity() const { |
269 | 546k | if (is_direct()) { |
270 | 546k | return N; |
271 | 546k | } else { |
272 | 0 | return _union.indirect_contents.capacity; |
273 | 0 | } |
274 | 546k | } prevector<36u, unsigned char, unsigned int, int>::capacity() const Line | Count | Source | 268 | 546k | size_t capacity() const { | 269 | 546k | if (is_direct()) { | 270 | 546k | return N; | 271 | 546k | } else { | 272 | 0 | return _union.indirect_contents.capacity; | 273 | 0 | } | 274 | 546k | } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::capacity() const Unexecuted instantiation: prevector<8u, int, unsigned int, int>::capacity() const Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::capacity() const Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::capacity() const |
275 | | |
276 | 15.9k | T& operator[](size_type pos) { |
277 | 15.9k | return *item_ptr(pos); |
278 | 15.9k | } prevector<36u, unsigned char, unsigned int, int>::operator[](unsigned int) Line | Count | Source | 276 | 15.9k | T& operator[](size_type pos) { | 277 | 15.9k | return *item_ptr(pos); | 278 | 15.9k | } |
Unexecuted instantiation: prevector<8u, int, unsigned int, int>::operator[](unsigned int) Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::operator[](unsigned int) Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::operator[](unsigned int) |
279 | | |
280 | 71.6k | const T& operator[](size_type pos) const { |
281 | 71.6k | return *item_ptr(pos); |
282 | 71.6k | } Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::operator[](unsigned int) const prevector<36u, unsigned char, unsigned int, int>::operator[](unsigned int) const Line | Count | Source | 280 | 71.6k | const T& operator[](size_type pos) const { | 281 | 71.6k | return *item_ptr(pos); | 282 | 71.6k | } |
Unexecuted instantiation: prevector<8u, int, unsigned int, int>::operator[](unsigned int) const |
283 | | |
284 | 74.6k | void resize(size_type new_size) { |
285 | 74.6k | size_type cur_size = size(); |
286 | 74.6k | if (cur_size == new_size) { |
287 | 74.6k | return; |
288 | 74.6k | } |
289 | 0 | if (cur_size > new_size) { |
290 | 0 | erase(item_ptr(new_size), end()); |
291 | 0 | return; |
292 | 0 | } |
293 | 0 | if (new_size > capacity()) { |
294 | 0 | change_capacity(new_size); |
295 | 0 | } |
296 | 0 | ptrdiff_t increase = new_size - cur_size; |
297 | 0 | fill(item_ptr(cur_size), increase); |
298 | 0 | _size += increase; |
299 | 0 | } prevector<36u, unsigned char, unsigned int, int>::resize(unsigned int) Line | Count | Source | 284 | 74.6k | void resize(size_type new_size) { | 285 | 74.6k | size_type cur_size = size(); | 286 | 74.6k | if (cur_size == new_size) { | 287 | 74.6k | return; | 288 | 74.6k | } | 289 | 0 | if (cur_size > new_size) { | 290 | 0 | erase(item_ptr(new_size), end()); | 291 | 0 | return; | 292 | 0 | } | 293 | 0 | if (new_size > capacity()) { | 294 | 0 | change_capacity(new_size); | 295 | 0 | } | 296 | 0 | ptrdiff_t increase = new_size - cur_size; | 297 | 0 | fill(item_ptr(cur_size), increase); | 298 | 0 | _size += increase; | 299 | 0 | } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::resize(unsigned int) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::resize(unsigned int) Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::resize(unsigned int) |
300 | | |
301 | 0 | void reserve(size_type new_capacity) { |
302 | 0 | if (new_capacity > capacity()) { |
303 | 0 | change_capacity(new_capacity); |
304 | 0 | } |
305 | 0 | } Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::reserve(unsigned int) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::reserve(unsigned int) |
306 | | |
307 | 29.9k | void shrink_to_fit() { |
308 | 29.9k | change_capacity(size()); |
309 | 29.9k | } prevector<36u, unsigned char, unsigned int, int>::shrink_to_fit() Line | Count | Source | 307 | 29.9k | void shrink_to_fit() { | 308 | 29.9k | change_capacity(size()); | 309 | 29.9k | } |
Unexecuted instantiation: prevector<8u, int, unsigned int, int>::shrink_to_fit() |
310 | | |
311 | 74.6k | void clear() { |
312 | 74.6k | resize(0); |
313 | 74.6k | } prevector<36u, unsigned char, unsigned int, int>::clear() Line | Count | Source | 311 | 74.6k | void clear() { | 312 | 74.6k | resize(0); | 313 | 74.6k | } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::clear() Unexecuted instantiation: prevector<8u, int, unsigned int, int>::clear() Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::clear() |
314 | | |
315 | 392k | iterator insert(iterator pos, const T& value) { |
316 | 392k | size_type p = pos - begin(); |
317 | 392k | size_type new_size = size() + 1; |
318 | 392k | if (capacity() < new_size) { |
319 | 0 | change_capacity(new_size + (new_size >> 1)); |
320 | 0 | } |
321 | 392k | T* ptr = item_ptr(p); |
322 | 392k | T* dst = ptr + 1; |
323 | 392k | memmove(dst, ptr, (size() - p) * sizeof(T)); |
324 | 392k | _size++; |
325 | 392k | new(static_cast<void*>(ptr)) T(value); |
326 | 392k | return iterator(ptr); |
327 | 392k | } prevector<36u, unsigned char, unsigned int, int>::insert(prevector<36u, unsigned char, unsigned int, int>::iterator, unsigned char const&) Line | Count | Source | 315 | 392k | iterator insert(iterator pos, const T& value) { | 316 | 392k | size_type p = pos - begin(); | 317 | 392k | size_type new_size = size() + 1; | 318 | 392k | if (capacity() < new_size) { | 319 | 0 | change_capacity(new_size + (new_size >> 1)); | 320 | 0 | } | 321 | 392k | T* ptr = item_ptr(p); | 322 | 392k | T* dst = ptr + 1; | 323 | 392k | memmove(dst, ptr, (size() - p) * sizeof(T)); | 324 | 392k | _size++; | 325 | 392k | new(static_cast<void*>(ptr)) T(value); | 326 | 392k | return iterator(ptr); | 327 | 392k | } |
Unexecuted instantiation: prevector<8u, int, unsigned int, int>::insert(prevector<8u, int, unsigned int, int>::iterator, int const&) |
328 | | |
329 | 0 | void insert(iterator pos, size_type count, const T& value) { |
330 | 0 | size_type p = pos - begin(); |
331 | 0 | size_type new_size = size() + count; |
332 | 0 | if (capacity() < new_size) { |
333 | 0 | change_capacity(new_size + (new_size >> 1)); |
334 | 0 | } |
335 | 0 | T* ptr = item_ptr(p); |
336 | 0 | T* dst = ptr + count; |
337 | 0 | memmove(dst, ptr, (size() - p) * sizeof(T)); |
338 | 0 | _size += count; |
339 | 0 | fill(item_ptr(p), count, value); |
340 | 0 | } Unexecuted instantiation: prevector<8u, int, unsigned int, int>::insert(prevector<8u, int, unsigned int, int>::iterator, unsigned int, int const&) Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::insert(prevector<36u, unsigned char, unsigned int, int>::iterator, unsigned int, unsigned char const&) |
341 | | |
342 | | template <std::input_iterator InputIterator> |
343 | 138k | void insert(iterator pos, InputIterator first, InputIterator last) { |
344 | 138k | size_type p = pos - begin(); |
345 | 138k | difference_type count = last - first; |
346 | 138k | size_type new_size = size() + count; |
347 | 138k | if (capacity() < new_size) { |
348 | 0 | change_capacity(new_size + (new_size >> 1)); |
349 | 0 | } |
350 | 138k | T* ptr = item_ptr(p); |
351 | 138k | T* dst = ptr + count; |
352 | 138k | memmove(dst, ptr, (size() - p) * sizeof(T)); |
353 | 138k | _size += count; |
354 | 138k | fill(ptr, first, last); |
355 | 138k | } Unexecuted instantiation: void prevector<36u, unsigned char, unsigned int, int>::insert<unsigned char const*>(prevector<36u, unsigned char, unsigned int, int>::iterator, unsigned char const*, unsigned char const*) void prevector<36u, unsigned char, unsigned int, int>::insert<std::__1::__wrap_iter<unsigned char const*>>(prevector<36u, unsigned char, unsigned int, int>::iterator, std::__1::__wrap_iter<unsigned char const*>, std::__1::__wrap_iter<unsigned char const*>) Line | Count | Source | 343 | 138k | void insert(iterator pos, InputIterator first, InputIterator last) { | 344 | 138k | size_type p = pos - begin(); | 345 | 138k | difference_type count = last - first; | 346 | 138k | size_type new_size = size() + count; | 347 | 138k | if (capacity() < new_size) { | 348 | 0 | change_capacity(new_size + (new_size >> 1)); | 349 | 0 | } | 350 | 138k | T* ptr = item_ptr(p); | 351 | 138k | T* dst = ptr + count; | 352 | 138k | memmove(dst, ptr, (size() - p) * sizeof(T)); | 353 | 138k | _size += count; | 354 | 138k | fill(ptr, first, last); | 355 | 138k | } |
Unexecuted instantiation: void prevector<36u, unsigned char, unsigned int, int>::insert<prevector<36u, unsigned char, unsigned int, int>::iterator>(prevector<36u, unsigned char, unsigned int, int>::iterator, prevector<36u, unsigned char, unsigned int, int>::iterator, prevector<36u, unsigned char, unsigned int, int>::iterator) Unexecuted instantiation: void prevector<8u, int, unsigned int, int>::insert<int*>(prevector<8u, int, unsigned int, int>::iterator, int*, int*) Unexecuted instantiation: void prevector<36u, unsigned char, unsigned int, int>::insert<std::__1::__wrap_iter<unsigned char*>>(prevector<36u, unsigned char, unsigned int, int>::iterator, std::__1::__wrap_iter<unsigned char*>, std::__1::__wrap_iter<unsigned char*>) Unexecuted instantiation: void prevector<35u, unsigned char, unsigned int, int>::insert<unsigned char*>(prevector<35u, unsigned char, unsigned int, int>::iterator, unsigned char*, unsigned char*) Unexecuted instantiation: void prevector<35u, unsigned char, unsigned int, int>::insert<unsigned char const*>(prevector<35u, unsigned char, unsigned int, int>::iterator, unsigned char const*, unsigned char const*) Unexecuted instantiation: void prevector<36u, unsigned char, unsigned int, int>::insert<prevector<36u, unsigned char, unsigned int, int>::const_iterator>(prevector<36u, unsigned char, unsigned int, int>::iterator, prevector<36u, unsigned char, unsigned int, int>::const_iterator, prevector<36u, unsigned char, unsigned int, int>::const_iterator) |
356 | | |
357 | 15.9k | inline void resize_uninitialized(size_type new_size) { |
358 | | // resize_uninitialized changes the size of the prevector but does not initialize it. |
359 | | // If size < new_size, the added elements must be initialized explicitly. |
360 | 15.9k | if (capacity() < new_size) { |
361 | 5.22k | change_capacity(new_size); |
362 | 5.22k | _size += new_size - size(); |
363 | 5.22k | return; |
364 | 5.22k | } |
365 | 10.6k | if (new_size < size()) { |
366 | 0 | erase(item_ptr(new_size), end()); |
367 | 10.6k | } else { |
368 | 10.6k | _size += new_size - size(); |
369 | 10.6k | } |
370 | 10.6k | } prevector<36u, unsigned char, unsigned int, int>::resize_uninitialized(unsigned int) Line | Count | Source | 357 | 15.9k | inline void resize_uninitialized(size_type new_size) { | 358 | | // resize_uninitialized changes the size of the prevector but does not initialize it. | 359 | | // If size < new_size, the added elements must be initialized explicitly. | 360 | 15.9k | if (capacity() < new_size) { | 361 | 5.22k | change_capacity(new_size); | 362 | 5.22k | _size += new_size - size(); | 363 | 5.22k | return; | 364 | 5.22k | } | 365 | 10.6k | if (new_size < size()) { | 366 | 0 | erase(item_ptr(new_size), end()); | 367 | 10.6k | } else { | 368 | 10.6k | _size += new_size - size(); | 369 | 10.6k | } | 370 | 10.6k | } |
Unexecuted instantiation: prevector<8u, int, unsigned int, int>::resize_uninitialized(unsigned int) |
371 | | |
372 | 0 | iterator erase(iterator pos) { |
373 | 0 | return erase(pos, pos + 1); |
374 | 0 | } Unexecuted instantiation: prevector<8u, int, unsigned int, int>::erase(prevector<8u, int, unsigned int, int>::iterator) Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::erase(prevector<33u, unsigned char, unsigned int, int>::iterator) |
375 | | |
376 | 0 | iterator erase(iterator first, iterator last) { |
377 | | // Erase is not allowed to the change the object's capacity. That means |
378 | | // that when starting with an indirectly allocated prevector with |
379 | | // size and capacity > N, the result may be a still indirectly allocated |
380 | | // prevector with size <= N and capacity > N. A shrink_to_fit() call is |
381 | | // necessary to switch to the (more efficient) directly allocated |
382 | | // representation (with capacity N and size <= N). |
383 | 0 | iterator p = first; |
384 | 0 | char* endp = (char*)&(*end()); |
385 | 0 | _size -= last - p; |
386 | 0 | memmove(&(*first), &(*last), endp - ((char*)(&(*last)))); |
387 | 0 | return first; |
388 | 0 | } Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::erase(prevector<36u, unsigned char, unsigned int, int>::iterator, prevector<36u, unsigned char, unsigned int, int>::iterator) Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::erase(prevector<16u, unsigned char, unsigned int, int>::iterator, prevector<16u, unsigned char, unsigned int, int>::iterator) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::erase(prevector<8u, int, unsigned int, int>::iterator, prevector<8u, int, unsigned int, int>::iterator) Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::erase(prevector<33u, unsigned char, unsigned int, int>::iterator, prevector<33u, unsigned char, unsigned int, int>::iterator) |
389 | | |
390 | | template<typename... Args> |
391 | 0 | void emplace_back(Args&&... args) { |
392 | 0 | size_type new_size = size() + 1; |
393 | 0 | if (capacity() < new_size) { |
394 | 0 | change_capacity(new_size + (new_size >> 1)); |
395 | 0 | } |
396 | 0 | new(item_ptr(size())) T(std::forward<Args>(args)...); |
397 | 0 | _size++; |
398 | 0 | } Unexecuted instantiation: void prevector<36u, unsigned char, unsigned int, int>::emplace_back<unsigned char const&>(unsigned char const&) Unexecuted instantiation: void prevector<8u, int, unsigned int, int>::emplace_back<int const&>(int const&) |
399 | | |
400 | 0 | void push_back(const T& value) { |
401 | 0 | emplace_back(value); |
402 | 0 | } Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::push_back(unsigned char const&) Unexecuted instantiation: prevector<8u, int, unsigned int, int>::push_back(int const&) |
403 | | |
404 | 0 | void pop_back() { |
405 | 0 | erase(end() - 1, end()); |
406 | 0 | } |
407 | | |
408 | | T& front() { |
409 | | return *item_ptr(0); |
410 | | } |
411 | | |
412 | | const T& front() const { |
413 | | return *item_ptr(0); |
414 | | } |
415 | | |
416 | 0 | T& back() { |
417 | 0 | return *item_ptr(size() - 1); |
418 | 0 | } |
419 | | |
420 | 11 | const T& back() const { |
421 | 11 | return *item_ptr(size() - 1); |
422 | 11 | } |
423 | | |
424 | | void swap(prevector<N, T, Size, Diff>& other) noexcept |
425 | 0 | { |
426 | 0 | std::swap(_union, other._union); |
427 | 0 | std::swap(_size, other._size); |
428 | 0 | } |
429 | | |
430 | 1.75M | ~prevector() { |
431 | 1.75M | if (!is_direct()) { |
432 | 23.6k | free(_union.indirect_contents.indirect); |
433 | 23.6k | _union.indirect_contents.indirect = nullptr; |
434 | 23.6k | } |
435 | 1.75M | } Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::~prevector() prevector<36u, unsigned char, unsigned int, int>::~prevector() Line | Count | Source | 430 | 1.75M | ~prevector() { | 431 | 1.75M | if (!is_direct()) { | 432 | 23.6k | free(_union.indirect_contents.indirect); | 433 | 23.6k | _union.indirect_contents.indirect = nullptr; | 434 | 23.6k | } | 435 | 1.75M | } |
Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::~prevector() Unexecuted instantiation: prevector<8u, int, unsigned int, int>::~prevector() Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::~prevector() |
436 | | |
437 | 32.0k | bool operator==(const prevector<N, T, Size, Diff>& other) const { |
438 | 32.0k | if (other.size() != size()) { |
439 | 0 | return false; |
440 | 0 | } |
441 | 32.0k | const_iterator b1 = begin(); |
442 | 32.0k | const_iterator b2 = other.begin(); |
443 | 32.0k | const_iterator e1 = end(); |
444 | 906k | while (b1 != e1) { |
445 | 873k | if ((*b1) != (*b2)) { |
446 | 0 | return false; |
447 | 0 | } |
448 | 873k | ++b1; |
449 | 873k | ++b2; |
450 | 873k | } |
451 | 32.0k | return true; |
452 | 32.0k | } prevector<36u, unsigned char, unsigned int, int>::operator==(prevector<36u, unsigned char, unsigned int, int> const&) const Line | Count | Source | 437 | 32.0k | bool operator==(const prevector<N, T, Size, Diff>& other) const { | 438 | 32.0k | if (other.size() != size()) { | 439 | 0 | return false; | 440 | 0 | } | 441 | 32.0k | const_iterator b1 = begin(); | 442 | 32.0k | const_iterator b2 = other.begin(); | 443 | 32.0k | const_iterator e1 = end(); | 444 | 906k | while (b1 != e1) { | 445 | 873k | if ((*b1) != (*b2)) { | 446 | 0 | return false; | 447 | 0 | } | 448 | 873k | ++b1; | 449 | 873k | ++b2; | 450 | 873k | } | 451 | 32.0k | return true; | 452 | 32.0k | } |
Unexecuted instantiation: prevector<8u, int, unsigned int, int>::operator==(prevector<8u, int, unsigned int, int> const&) const Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::operator==(prevector<16u, unsigned char, unsigned int, int> const&) const |
453 | | |
454 | 0 | bool operator!=(const prevector<N, T, Size, Diff>& other) const { |
455 | 0 | return !(*this == other); |
456 | 0 | } |
457 | | |
458 | 60.2k | bool operator<(const prevector<N, T, Size, Diff>& other) const { |
459 | 60.2k | if (size() < other.size()) { |
460 | 0 | return true; |
461 | 0 | } |
462 | 60.2k | if (size() > other.size()) { |
463 | 0 | return false; |
464 | 0 | } |
465 | 60.2k | const_iterator b1 = begin(); |
466 | 60.2k | const_iterator b2 = other.begin(); |
467 | 60.2k | const_iterator e1 = end(); |
468 | 1.30M | while (b1 != e1) { |
469 | 1.25M | if ((*b1) < (*b2)) { |
470 | 10.5k | return true; |
471 | 10.5k | } |
472 | 1.24M | if ((*b2) < (*b1)) { |
473 | 5.58k | return false; |
474 | 5.58k | } |
475 | 1.24M | ++b1; |
476 | 1.24M | ++b2; |
477 | 1.24M | } |
478 | 44.1k | return false; |
479 | 60.2k | } prevector<36u, unsigned char, unsigned int, int>::operator<(prevector<36u, unsigned char, unsigned int, int> const&) const Line | Count | Source | 458 | 60.2k | bool operator<(const prevector<N, T, Size, Diff>& other) const { | 459 | 60.2k | if (size() < other.size()) { | 460 | 0 | return true; | 461 | 0 | } | 462 | 60.2k | if (size() > other.size()) { | 463 | 0 | return false; | 464 | 0 | } | 465 | 60.2k | const_iterator b1 = begin(); | 466 | 60.2k | const_iterator b2 = other.begin(); | 467 | 60.2k | const_iterator e1 = end(); | 468 | 1.30M | while (b1 != e1) { | 469 | 1.25M | if ((*b1) < (*b2)) { | 470 | 10.5k | return true; | 471 | 10.5k | } | 472 | 1.24M | if ((*b2) < (*b1)) { | 473 | 5.58k | return false; | 474 | 5.58k | } | 475 | 1.24M | ++b1; | 476 | 1.24M | ++b2; | 477 | 1.24M | } | 478 | 44.1k | return false; | 479 | 60.2k | } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::operator<(prevector<16u, unsigned char, unsigned int, int> const&) const |
480 | | |
481 | 27.1k | size_t allocated_memory() const { |
482 | 27.1k | if (is_direct()) { |
483 | 25.8k | return 0; |
484 | 25.8k | } else { |
485 | 1.34k | return ((size_t)(sizeof(T))) * _union.indirect_contents.capacity; |
486 | 1.34k | } |
487 | 27.1k | } |
488 | | |
489 | 0 | value_type* data() { |
490 | 0 | return item_ptr(0); |
491 | 0 | } Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::data() Unexecuted instantiation: prevector<36u, unsigned char, unsigned int, int>::data() Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::data() Unexecuted instantiation: prevector<35u, unsigned char, unsigned int, int>::data() |
492 | | |
493 | 281k | const value_type* data() const { |
494 | 281k | return item_ptr(0); |
495 | 281k | } prevector<36u, unsigned char, unsigned int, int>::data() const Line | Count | Source | 493 | 281k | const value_type* data() const { | 494 | 281k | return item_ptr(0); | 495 | 281k | } |
Unexecuted instantiation: prevector<16u, unsigned char, unsigned int, int>::data() const Unexecuted instantiation: prevector<33u, unsigned char, unsigned int, int>::data() const |
496 | | }; |
497 | | |
498 | | #endif // BITCOIN_PREVECTOR_H |