fuzz coverage

Coverage Report

Created: 2025-08-28 15:26

/Users/eugenesiegel/btc/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
1.69M
        iterator(T* ptr_) : ptr(ptr_) {}
_ZN9prevectorILj16EhjiE8iteratorC2EPh
Line
Count
Source
58
238k
        iterator(T* ptr_) : ptr(ptr_) {}
_ZN9prevectorILj28EhjiE8iteratorC2EPh
Line
Count
Source
58
1.45M
        iterator(T* ptr_) : ptr(ptr_) {}
Unexecuted instantiation: _ZN9prevectorILj8EijiE8iteratorC2EPi
Unexecuted instantiation: _ZN9prevectorILj33EhjiE8iteratorC2EPh
_ZN9prevectorILj35EhjiE8iteratorC2EPh
Line
Count
Source
58
232
        iterator(T* ptr_) : ptr(ptr_) {}
59
1.65M
        T& operator*() const { return *ptr; }
_ZNK9prevectorILj28EhjiE8iteratordeEv
Line
Count
Source
59
1.17M
        T& operator*() const { return *ptr; }
_ZNK9prevectorILj16EhjiE8iteratordeEv
Line
Count
Source
59
476k
        T& operator*() const { return *ptr; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE8iteratordeEv
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8iteratordeEv
_ZNK9prevectorILj35EhjiE8iteratordeEv
Line
Count
Source
59
232
        T& operator*() const { return *ptr; }
60
61.3k
        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
643k
        difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }
_ZmiN9prevectorILj28EhjiE8iteratorES1_
Line
Count
Source
66
563k
        difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }
_ZmiN9prevectorILj16EhjiE8iteratorES1_
Line
Count
Source
66
79.3k
        difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }
Unexecuted instantiation: _ZmiN9prevectorILj8EijiE8iteratorES1_
Unexecuted instantiation: _ZmiN9prevectorILj33EhjiE8iteratorES1_
_ZmiN9prevectorILj35EhjiE8iteratorES1_
Line
Count
Source
66
116
        difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }
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
6.96M
        const_iterator(const T* ptr_) : ptr(ptr_) {}
_ZN9prevectorILj16EhjiE14const_iteratorC2EPKh
Line
Count
Source
109
1.01M
        const_iterator(const T* ptr_) : ptr(ptr_) {}
_ZN9prevectorILj28EhjiE14const_iteratorC2EPKh
Line
Count
Source
109
5.94M
        const_iterator(const T* ptr_) : ptr(ptr_) {}
Unexecuted instantiation: _ZN9prevectorILj8EijiE14const_iteratorC2EPKi
110
0
        const_iterator(iterator x) : ptr(&(*x)) {}
111
56.4M
        const T& operator*() const { return *ptr; }
_ZNK9prevectorILj28EhjiE14const_iteratordeEv
Line
Count
Source
111
51.0M
        const T& operator*() const { return *ptr; }
_ZNK9prevectorILj16EhjiE14const_iteratordeEv
Line
Count
Source
111
5.38M
        const T& operator*() const { return *ptr; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratordeEv
112
565k
        const T* operator->() const { return ptr; }
_ZNK9prevectorILj16EhjiE14const_iteratorptEv
Line
Count
Source
112
233k
        const T* operator->() const { return ptr; }
_ZNK9prevectorILj28EhjiE14const_iteratorptEv
Line
Count
Source
112
331k
        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
52.7M
        const_iterator& operator++() { ptr++; return *this; }
_ZN9prevectorILj28EhjiE14const_iteratorppEv
Line
Count
Source
114
47.5M
        const_iterator& operator++() { ptr++; return *this; }
_ZN9prevectorILj16EhjiE14const_iteratorppEv
Line
Count
Source
114
5.21M
        const_iterator& operator++() { ptr++; return *this; }
Unexecuted instantiation: _ZN9prevectorILj8EijiE14const_iteratorppEv
115
0
        const_iterator& operator--() { ptr--; return *this; }
116
383k
        const_iterator operator++(int) { const_iterator copy(*this); ++(*this); return copy; }
117
        const_iterator operator--(int) { const_iterator copy(*this); --(*this); return copy; }
118
1.72M
        difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); }
_ZmiN9prevectorILj16EhjiE14const_iteratorES1_
Line
Count
Source
118
41.2k
        difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); }
_ZmiN9prevectorILj28EhjiE14const_iteratorES1_
Line
Count
Source
118
1.68M
        difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); }
Unexecuted instantiation: _ZmiN9prevectorILj8EijiE14const_iteratorES1_
119
176k
        const_iterator operator+(size_type n) const { return const_iterator(ptr + n); }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratorplEj
_ZNK9prevectorILj28EhjiE14const_iteratorplEj
Line
Count
Source
119
176k
        const_iterator operator+(size_type n) const { return const_iterator(ptr + n); }
120
        const_iterator friend operator+(size_type n, const_iterator x) { return x + n; }
121
299k
        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; }
125
52.8M
        bool operator!=(const_iterator x) const { return ptr != x.ptr; }
_ZNK9prevectorILj28EhjiE14const_iteratorneES1_
Line
Count
Source
125
47.2M
        bool operator!=(const_iterator x) const { return ptr != x.ptr; }
_ZNK9prevectorILj16EhjiE14const_iteratorneES1_
Line
Count
Source
125
5.57M
        bool operator!=(const_iterator x) const { return ptr != x.ptr; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratorneES1_
126
383k
        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
644k
        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
4.86M
    T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
_ZN9prevectorILj28EhjiE10direct_ptrEi
Line
Count
Source
169
4.03M
    T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE10direct_ptrEi
_ZN9prevectorILj16EhjiE10direct_ptrEi
Line
Count
Source
169
826k
    T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
Unexecuted instantiation: _ZN9prevectorILj8EijiE10direct_ptrEi
_ZN9prevectorILj35EhjiE10direct_ptrEi
Line
Count
Source
169
464
    T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
170
5.09M
    const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; }
_ZNK9prevectorILj28EhjiE10direct_ptrEi
Line
Count
Source
170
3.68M
    const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; }
_ZNK9prevectorILj16EhjiE10direct_ptrEi
Line
Count
Source
170
1.41M
    const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE10direct_ptrEi
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE10direct_ptrEi
171
2.31M
    T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; }
_ZN9prevectorILj28EhjiE12indirect_ptrEi
Line
Count
Source
171
2.25M
    T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE12indirect_ptrEi
_ZN9prevectorILj16EhjiE12indirect_ptrEi
Line
Count
Source
171
61.8k
    T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; }
Unexecuted instantiation: _ZN9prevectorILj8EijiE12indirect_ptrEi
Unexecuted instantiation: _ZN9prevectorILj35EhjiE12indirect_ptrEi
172
6.28M
    const T* indirect_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.indirect_contents.indirect) + pos; }
_ZNK9prevectorILj28EhjiE12indirect_ptrEi
Line
Count
Source
172
6.20M
    const T* indirect_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.indirect_contents.indirect) + pos; }
_ZNK9prevectorILj16EhjiE12indirect_ptrEi
Line
Count
Source
172
85.8k
    const T* indirect_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.indirect_contents.indirect) + pos; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE12indirect_ptrEi
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE12indirect_ptrEi
173
54.5M
    bool is_direct() const { return _size <= N; }
_ZNK9prevectorILj28EhjiE9is_directEv
Line
Count
Source
173
49.4M
    bool is_direct() const { return _size <= N; }
_ZNK9prevectorILj33EhjiE9is_directEv
Line
Count
Source
173
2.27k
    bool is_direct() const { return _size <= N; }
_ZNK9prevectorILj16EhjiE9is_directEv
Line
Count
Source
173
5.05M
    bool is_direct() const { return _size <= N; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE9is_directEv
_ZNK9prevectorILj35EhjiE9is_directEv
Line
Count
Source
173
1.10k
    bool is_direct() const { return _size <= N; }
174
175
3.67M
    void change_capacity(size_type new_capacity) {
176
3.67M
        if (new_capacity <= N) {
177
2.01M
            if (!is_direct()) {
178
13.0k
                T* indirect = indirect_ptr(0);
179
13.0k
                T* src = indirect;
180
13.0k
                T* dst = direct_ptr(0);
181
13.0k
                memcpy(dst, src, size() * sizeof(T));
182
13.0k
                free(indirect);
183
13.0k
                _size -= N + 1;
184
13.0k
            }
185
2.01M
        } else {
186
1.66M
            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
1.66M
            } else {
194
1.66M
                char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
195
1.66M
                assert(new_indirect);
196
1.66M
                T* src = direct_ptr(0);
197
1.66M
                T* dst = reinterpret_cast<T*>(new_indirect);
198
1.66M
                memcpy(dst, src, size() * sizeof(T));
199
1.66M
                _union.indirect_contents.indirect = new_indirect;
200
1.66M
                _union.indirect_contents.capacity = new_capacity;
201
1.66M
                _size += N + 1;
202
1.66M
            }
203
1.66M
        }
204
3.67M
    }
_ZN9prevectorILj28EhjiE15change_capacityEj
Line
Count
Source
175
3.18M
    void change_capacity(size_type new_capacity) {
176
3.18M
        if (new_capacity <= N) {
177
1.56M
            if (!is_direct()) {
178
13.0k
                T* indirect = indirect_ptr(0);
179
13.0k
                T* src = indirect;
180
13.0k
                T* dst = direct_ptr(0);
181
13.0k
                memcpy(dst, src, size() * sizeof(T));
182
13.0k
                free(indirect);
183
13.0k
                _size -= N + 1;
184
13.0k
            }
185
1.61M
        } else {
186
1.61M
            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
1.61M
            } else {
194
1.61M
                char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
195
1.61M
                assert(new_indirect);
196
1.61M
                T* src = direct_ptr(0);
197
1.61M
                T* dst = reinterpret_cast<T*>(new_indirect);
198
1.61M
                memcpy(dst, src, size() * sizeof(T));
199
1.61M
                _union.indirect_contents.indirect = new_indirect;
200
1.61M
                _union.indirect_contents.capacity = new_capacity;
201
1.61M
                _size += N + 1;
202
1.61M
            }
203
1.61M
        }
204
3.18M
    }
_ZN9prevectorILj16EhjiE15change_capacityEj
Line
Count
Source
175
494k
    void change_capacity(size_type new_capacity) {
176
494k
        if (new_capacity <= N) {
177
443k
            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
443k
        } else {
186
50.6k
            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
50.6k
            } else {
194
50.6k
                char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
195
50.6k
                assert(new_indirect);
196
50.6k
                T* src = direct_ptr(0);
197
50.6k
                T* dst = reinterpret_cast<T*>(new_indirect);
198
50.6k
                memcpy(dst, src, size() * sizeof(T));
199
50.6k
                _union.indirect_contents.indirect = new_indirect;
200
50.6k
                _union.indirect_contents.capacity = new_capacity;
201
50.6k
                _size += N + 1;
202
50.6k
            }
203
50.6k
        }
204
494k
    }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE15change_capacityEj
Unexecuted instantiation: _ZN9prevectorILj8EijiE15change_capacityEj
_ZN9prevectorILj35EhjiE15change_capacityEj
Line
Count
Source
175
58
    void change_capacity(size_type new_capacity) {
176
58
        if (new_capacity <= N) {
177
58
            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
58
        } else {
186
0
            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
0
            } else {
194
0
                char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
195
0
                assert(new_indirect);
196
0
                T* src = direct_ptr(0);
197
0
                T* dst = reinterpret_cast<T*>(new_indirect);
198
0
                memcpy(dst, src, size() * sizeof(T));
199
0
                _union.indirect_contents.indirect = new_indirect;
200
0
                _union.indirect_contents.capacity = new_capacity;
201
0
                _size += N + 1;
202
0
            }
203
0
        }
204
58
    }
205
206
5.48M
    T* item_ptr(difference_type pos) { return is_direct() ? 
direct_ptr(pos)3.18M
:
indirect_ptr(pos)2.30M
; }
_ZN9prevectorILj28EhjiE8item_ptrEi
Line
Count
Source
206
4.64M
    T* item_ptr(difference_type pos) { return is_direct() ? 
direct_ptr(pos)2.40M
:
indirect_ptr(pos)2.23M
; }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE8item_ptrEi
_ZN9prevectorILj16EhjiE8item_ptrEi
Line
Count
Source
206
837k
    T* item_ptr(difference_type pos) { return is_direct() ? 
direct_ptr(pos)776k
:
indirect_ptr(pos)61.8k
; }
Unexecuted instantiation: _ZN9prevectorILj8EijiE8item_ptrEi
_ZN9prevectorILj35EhjiE8item_ptrEi
Line
Count
Source
206
464
    T* item_ptr(difference_type pos) { return is_direct() ? direct_ptr(pos) : 
indirect_ptr(pos)0
; }
207
11.3M
    const T* item_ptr(difference_type pos) const { return is_direct() ? 
direct_ptr(pos)5.09M
:
indirect_ptr(pos)6.28M
; }
_ZNK9prevectorILj28EhjiE8item_ptrEi
Line
Count
Source
207
9.88M
    const T* item_ptr(difference_type pos) const { return is_direct() ? 
direct_ptr(pos)3.68M
:
indirect_ptr(pos)6.20M
; }
_ZNK9prevectorILj16EhjiE8item_ptrEi
Line
Count
Source
207
1.49M
    const T* item_ptr(difference_type pos) const { return is_direct() ? 
direct_ptr(pos)1.41M
:
indirect_ptr(pos)85.8k
; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE8item_ptrEi
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8item_ptrEi
208
209
412k
    void fill(T* dst, ptrdiff_t count, const T& value = T{}) {
210
412k
        std::fill_n(dst, count, value);
211
412k
    }
_ZN9prevectorILj28EhjiE4fillEPhlRKh
Line
Count
Source
209
203k
    void fill(T* dst, ptrdiff_t count, const T& value = T{}) {
210
203k
        std::fill_n(dst, count, value);
211
203k
    }
_ZN9prevectorILj16EhjiE4fillEPhlRKh
Line
Count
Source
209
208k
    void fill(T* dst, ptrdiff_t count, const T& value = T{}) {
210
208k
        std::fill_n(dst, count, value);
211
208k
    }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE4fillEPhlRKh
Unexecuted instantiation: _ZN9prevectorILj8EijiE4fillEPilRKi
212
213
    template <std::input_iterator InputIterator>
214
2.55M
    void fill(T* dst, InputIterator first, InputIterator last) {
215
57.5M
        while (first != last) {
216
54.9M
            new(static_cast<void*>(dst)) T(*first);
217
54.9M
            ++dst;
218
54.9M
            ++first;
219
54.9M
        }
220
2.55M
    }
Unexecuted instantiation: _ZN9prevectorILj28EhjiE4fillITkNSt3__114input_iteratorEPKhEEvPhT_S6_
_ZN9prevectorILj28EhjiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvPhT_S8_
Line
Count
Source
214
241k
    void fill(T* dst, InputIterator first, InputIterator last) {
215
6.23M
        while (first != last) {
216
5.99M
            new(static_cast<void*>(dst)) T(*first);
217
5.99M
            ++dst;
218
5.99M
            ++first;
219
5.99M
        }
220
241k
    }
_ZN9prevectorILj28EhjiE4fillITkNSt3__114input_iteratorENS0_14const_iteratorEEEvPhT_S5_
Line
Count
Source
214
1.96M
    void fill(T* dst, InputIterator first, InputIterator last) {
215
45.3M
        while (first != last) {
216
43.4M
            new(static_cast<void*>(dst)) T(*first);
217
43.4M
            ++dst;
218
43.4M
            ++first;
219
43.4M
        }
220
1.96M
    }
_ZN9prevectorILj16EhjiE4fillITkNSt3__114input_iteratorENS0_14const_iteratorEEEvPhT_S5_
Line
Count
Source
214
326k
    void fill(T* dst, InputIterator first, InputIterator last) {
215
5.51M
        while (first != last) {
216
5.18M
            new(static_cast<void*>(dst)) T(*first);
217
5.18M
            ++dst;
218
5.18M
            ++first;
219
5.18M
        }
220
326k
    }
Unexecuted instantiation: _ZN9prevectorILj28EhjiE4fillITkNSt3__114input_iteratorENS0_8iteratorEEEvPhT_S5_
Unexecuted instantiation: _ZN9prevectorILj8EijiE4fillITkNSt3__114input_iteratorEPiEEvS3_T_S4_
Unexecuted instantiation: _ZN9prevectorILj8EijiE4fillITkNSt3__114input_iteratorENS0_14const_iteratorEEEvPiT_S5_
Unexecuted instantiation: _ZN9prevectorILj8EijiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPKiEEEEvPiT_S8_
Unexecuted instantiation: _ZN9prevectorILj33EhjiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvPhT_S8_
Unexecuted instantiation: _ZN9prevectorILj28EhjiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPhEEEEvS4_T_S6_
_ZN9prevectorILj16EhjiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvPhT_S8_
Line
Count
Source
214
20.9k
    void fill(T* dst, InputIterator first, InputIterator last) {
215
356k
        while (first != last) {
216
335k
            new(static_cast<void*>(dst)) T(*first);
217
335k
            ++dst;
218
335k
            ++first;
219
335k
        }
220
20.9k
    }
_ZN9prevectorILj16EhjiE4fillITkNSt3__114input_iteratorEPhEEvS3_T_S4_
Line
Count
Source
214
5.58k
    void fill(T* dst, InputIterator first, InputIterator last) {
215
61.4k
        while (first != last) {
216
55.8k
            new(static_cast<void*>(dst)) T(*first);
217
55.8k
            ++dst;
218
55.8k
            ++first;
219
55.8k
        }
220
5.58k
    }
Unexecuted instantiation: _ZN9prevectorILj16EhjiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPhEEEEvS4_T_S6_
Unexecuted instantiation: _ZN9prevectorILj16EhjiE4fillITkNSt3__114input_iteratorEPKhEEvPhT_S6_
_ZN9prevectorILj35EhjiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvPhT_S8_
Line
Count
Source
214
58
    void fill(T* dst, InputIterator first, InputIterator last) {
215
1.91k
        while (first != last) {
216
1.85k
            new(static_cast<void*>(dst)) T(*first);
217
1.85k
            ++dst;
218
1.85k
            ++first;
219
1.85k
        }
220
58
    }
_ZN9prevectorILj35EhjiE4fillITkNSt3__114input_iteratorEPhEEvS3_T_S4_
Line
Count
Source
214
58
    void fill(T* dst, InputIterator first, InputIterator last) {
215
174
        while (first != last) {
216
116
            new(static_cast<void*>(dst)) T(*first);
217
116
            ++dst;
218
116
            ++first;
219
116
        }
220
58
    }
_ZN9prevectorILj35EhjiE4fillITkNSt3__114input_iteratorEPKhEEvPhT_S6_
Line
Count
Source
214
58
    void fill(T* dst, InputIterator first, InputIterator last) {
215
116
        while (first != last) {
216
58
            new(static_cast<void*>(dst)) T(*first);
217
58
            ++dst;
218
58
            ++first;
219
58
        }
220
58
    }
221
222
public:
223
9
    void assign(size_type n, const T& val) {
224
9
        clear();
225
9
        if (capacity() < n) {
226
0
            change_capacity(n);
227
0
        }
228
9
        _size += n;
229
9
        fill(item_ptr(0), n, val);
230
9
    }
_ZN9prevectorILj16EhjiE6assignEjRKh
Line
Count
Source
223
9
    void assign(size_type n, const T& val) {
224
9
        clear();
225
9
        if (capacity() < n) {
226
0
            change_capacity(n);
227
0
        }
228
9
        _size += n;
229
9
        fill(item_ptr(0), n, val);
230
9
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE6assignEjRKi
231
232
    template <std::input_iterator InputIterator>
233
613k
    void assign(InputIterator first, InputIterator last) {
234
613k
        size_type n = last - first;
235
613k
        clear();
236
613k
        if (capacity() < n) {
237
287k
            change_capacity(n);
238
287k
        }
239
613k
        _size += n;
240
613k
        fill(item_ptr(0), first, last);
241
613k
    }
_ZN9prevectorILj16EhjiE6assignITkNSt3__114input_iteratorENS0_14const_iteratorEEEvT_S4_
Line
Count
Source
233
41.0k
    void assign(InputIterator first, InputIterator last) {
234
41.0k
        size_type n = last - first;
235
41.0k
        clear();
236
41.0k
        if (capacity() < n) {
237
137
            change_capacity(n);
238
137
        }
239
41.0k
        _size += n;
240
41.0k
        fill(item_ptr(0), first, last);
241
41.0k
    }
_ZN9prevectorILj28EhjiE6assignITkNSt3__114input_iteratorENS0_14const_iteratorEEEvT_S4_
Line
Count
Source
233
546k
    void assign(InputIterator first, InputIterator last) {
234
546k
        size_type n = last - first;
235
546k
        clear();
236
546k
        if (capacity() < n) {
237
287k
            change_capacity(n);
238
287k
        }
239
546k
        _size += n;
240
546k
        fill(item_ptr(0), first, last);
241
546k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE6assignITkNSt3__114input_iteratorENS0_14const_iteratorEEEvT_S4_
Unexecuted instantiation: _ZN9prevectorILj33EhjiE6assignITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvT_S7_
_ZN9prevectorILj16EhjiE6assignITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvT_S7_
Line
Count
Source
233
20.9k
    void assign(InputIterator first, InputIterator last) {
234
20.9k
        size_type n = last - first;
235
20.9k
        clear();
236
20.9k
        if (capacity() < n) {
237
0
            change_capacity(n);
238
0
        }
239
20.9k
        _size += n;
240
20.9k
        fill(item_ptr(0), first, last);
241
20.9k
    }
_ZN9prevectorILj16EhjiE6assignITkNSt3__114input_iteratorEPhEEvT_S4_
Line
Count
Source
233
5.58k
    void assign(InputIterator first, InputIterator last) {
234
5.58k
        size_type n = last - first;
235
5.58k
        clear();
236
5.58k
        if (capacity() < n) {
237
0
            change_capacity(n);
238
0
        }
239
5.58k
        _size += n;
240
5.58k
        fill(item_ptr(0), first, last);
241
5.58k
    }
Unexecuted instantiation: _ZN9prevectorILj16EhjiE6assignITkNSt3__114input_iteratorENS2_11__wrap_iterIPhEEEEvT_S6_
Unexecuted instantiation: _ZN9prevectorILj16EhjiE6assignITkNSt3__114input_iteratorEPKhEEvT_S5_
242
243
1.89M
    prevector() = default;
_ZN9prevectorILj28EhjiEC2Ev
Line
Count
Source
243
1.89M
    prevector() = default;
_ZN9prevectorILj33EhjiEC2Ev
Line
Count
Source
243
2.27k
    prevector() = default;
Unexecuted instantiation: _ZN9prevectorILj8EijiEC2Ev
244
245
    explicit prevector(size_type n) {
246
        resize(n);
247
    }
248
249
197k
    explicit prevector(size_type n, const T& val) {
250
197k
        change_capacity(n);
251
197k
        _size += n;
252
197k
        fill(item_ptr(0), n, val);
253
197k
    }
Unexecuted instantiation: _ZN9prevectorILj33EhjiEC2EjRKh
_ZN9prevectorILj16EhjiEC2EjRKh
Line
Count
Source
249
197k
    explicit prevector(size_type n, const T& val) {
250
197k
        change_capacity(n);
251
197k
        _size += n;
252
197k
        fill(item_ptr(0), n, val);
253
197k
    }
254
255
    template <std::input_iterator InputIterator>
256
35.7k
    prevector(InputIterator first, InputIterator last) {
257
35.7k
        size_type n = last - first;
258
35.7k
        change_capacity(n);
259
35.7k
        _size += n;
260
35.7k
        fill(item_ptr(0), first, last);
261
35.7k
    }
_ZN9prevectorILj28EhjiEC2ITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEET_S7_
Line
Count
Source
256
35.6k
    prevector(InputIterator first, InputIterator last) {
257
35.6k
        size_type n = last - first;
258
35.6k
        change_capacity(n);
259
35.6k
        _size += n;
260
35.6k
        fill(item_ptr(0), first, last);
261
35.6k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiEC2ITkNSt3__114input_iteratorENS2_11__wrap_iterIPKiEEEET_S7_
Unexecuted instantiation: _ZN9prevectorILj8EijiEC2ITkNSt3__114input_iteratorENS0_14const_iteratorEEET_S4_
Unexecuted instantiation: _ZN9prevectorILj28EhjiEC2ITkNSt3__114input_iteratorENS2_11__wrap_iterIPhEEEET_S6_
_ZN9prevectorILj35EhjiEC2ITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEET_S7_
Line
Count
Source
256
58
    prevector(InputIterator first, InputIterator last) {
257
58
        size_type n = last - first;
258
58
        change_capacity(n);
259
58
        _size += n;
260
58
        fill(item_ptr(0), first, last);
261
58
    }
Unexecuted instantiation: _ZN9prevectorILj28EhjiEC2ITkNSt3__114input_iteratorENS0_14const_iteratorEEET_S4_
262
263
1.70M
    prevector(const prevector<N, T, Size, Diff>& other) {
264
1.70M
        size_type n = other.size();
265
1.70M
        change_capacity(n);
266
1.70M
        _size += n;
267
1.70M
        fill(item_ptr(0), other.begin(),  other.end());
268
1.70M
    }
_ZN9prevectorILj16EhjiEC2ERKS0_
Line
Count
Source
263
285k
    prevector(const prevector<N, T, Size, Diff>& other) {
264
285k
        size_type n = other.size();
265
285k
        change_capacity(n);
266
285k
        _size += n;
267
285k
        fill(item_ptr(0), other.begin(),  other.end());
268
285k
    }
_ZN9prevectorILj28EhjiEC2ERKS0_
Line
Count
Source
263
1.41M
    prevector(const prevector<N, T, Size, Diff>& other) {
264
1.41M
        size_type n = other.size();
265
1.41M
        change_capacity(n);
266
1.41M
        _size += n;
267
1.41M
        fill(item_ptr(0), other.begin(),  other.end());
268
1.41M
    }
269
270
    prevector(prevector<N, T, Size, Diff>&& other) noexcept
271
486k
        : _union(std::move(other._union)), _size(other._size)
272
486k
    {
273
486k
        other._size = 0;
274
486k
    }
_ZN9prevectorILj16EhjiEC2EOS0_
Line
Count
Source
271
3.60k
        : _union(std::move(other._union)), _size(other._size)
272
3.60k
    {
273
3.60k
        other._size = 0;
274
3.60k
    }
_ZN9prevectorILj28EhjiEC2EOS0_
Line
Count
Source
271
483k
        : _union(std::move(other._union)), _size(other._size)
272
483k
    {
273
483k
        other._size = 0;
274
483k
    }
275
276
587k
    prevector& operator=(const prevector<N, T, Size, Diff>& other) {
277
587k
        if (&other == this) {
278
0
            return *this;
279
0
        }
280
587k
        assign(other.begin(), other.end());
281
587k
        return *this;
282
587k
    }
_ZN9prevectorILj16EhjiEaSERKS0_
Line
Count
Source
276
41.0k
    prevector& operator=(const prevector<N, T, Size, Diff>& other) {
277
41.0k
        if (&other == this) {
278
0
            return *this;
279
0
        }
280
41.0k
        assign(other.begin(), other.end());
281
41.0k
        return *this;
282
41.0k
    }
_ZN9prevectorILj28EhjiEaSERKS0_
Line
Count
Source
276
546k
    prevector& operator=(const prevector<N, T, Size, Diff>& other) {
277
546k
        if (&other == this) {
278
0
            return *this;
279
0
        }
280
546k
        assign(other.begin(), other.end());
281
546k
        return *this;
282
546k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiEaSERKS0_
283
284
318k
    prevector& operator=(prevector<N, T, Size, Diff>&& other) noexcept {
285
318k
        if (!is_direct()) {
286
556
            free(_union.indirect_contents.indirect);
287
556
        }
288
318k
        _union = std::move(other._union);
289
318k
        _size = other._size;
290
318k
        other._size = 0;
291
318k
        return *this;
292
318k
    }
Unexecuted instantiation: _ZN9prevectorILj16EhjiEaSEOS0_
_ZN9prevectorILj28EhjiEaSEOS0_
Line
Count
Source
284
318k
    prevector& operator=(prevector<N, T, Size, Diff>&& other) noexcept {
285
318k
        if (!is_direct()) {
286
556
            free(_union.indirect_contents.indirect);
287
556
        }
288
318k
        _union = std::move(other._union);
289
318k
        _size = other._size;
290
318k
        other._size = 0;
291
318k
        return *this;
292
318k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiEaSEOS0_
293
294
27.2M
    size_type size() const {
295
27.2M
        return is_direct() ? 
_size16.4M
:
_size - N - 110.8M
;
296
27.2M
    }
_ZNK9prevectorILj28EhjiE4sizeEv
Line
Count
Source
294
25.6M
    size_type size() const {
295
25.6M
        return is_direct() ? 
_size14.8M
:
_size - N - 110.7M
;
296
25.6M
    }
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE4sizeEv
_ZNK9prevectorILj16EhjiE4sizeEv
Line
Count
Source
294
1.66M
    size_type size() const {
295
1.66M
        return is_direct() ? 
_size1.56M
:
_size - N - 196.7k
;
296
1.66M
    }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE4sizeEv
_ZNK9prevectorILj35EhjiE4sizeEv
Line
Count
Source
294
406
    size_type size() const {
295
406
        return is_direct() ? _size : 
_size - N - 10
;
296
406
    }
297
298
4.65M
    bool empty() const {
299
4.65M
        return size() == 0;
300
4.65M
    }
_ZNK9prevectorILj28EhjiE5emptyEv
Line
Count
Source
298
4.65M
    bool empty() const {
299
4.65M
        return size() == 0;
300
4.65M
    }
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE5emptyEv
Unexecuted instantiation: _ZNK9prevectorILj8EijiE5emptyEv
301
302
552k
    iterator begin() { return iterator(item_ptr(0)); }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE5beginEv
_ZN9prevectorILj28EhjiE5beginEv
Line
Count
Source
302
551k
    iterator begin() { return iterator(item_ptr(0)); }
Unexecuted instantiation: _ZN9prevectorILj16EhjiE5beginEv
Unexecuted instantiation: _ZN9prevectorILj8EijiE5beginEv
_ZN9prevectorILj35EhjiE5beginEv
Line
Count
Source
302
116
    iterator begin() { return iterator(item_ptr(0)); }
303
3.33M
    const_iterator begin() const { return const_iterator(item_ptr(0)); }
_ZNK9prevectorILj28EhjiE5beginEv
Line
Count
Source
303
2.68M
    const_iterator begin() const { return const_iterator(item_ptr(0)); }
_ZNK9prevectorILj16EhjiE5beginEv
Line
Count
Source
303
648k
    const_iterator begin() const { return const_iterator(item_ptr(0)); }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE5beginEv
304
736k
    iterator end() { return iterator(item_ptr(size())); }
_ZN9prevectorILj28EhjiE3endEv
Line
Count
Source
304
577k
    iterator end() { return iterator(item_ptr(size())); }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE3endEv
_ZN9prevectorILj16EhjiE3endEv
Line
Count
Source
304
158k
    iterator end() { return iterator(item_ptr(size())); }
Unexecuted instantiation: _ZN9prevectorILj8EijiE3endEv
_ZN9prevectorILj35EhjiE3endEv
Line
Count
Source
304
116
    iterator end() { return iterator(item_ptr(size())); }
305
3.45M
    const_iterator end() const { return const_iterator(item_ptr(size())); }
_ZNK9prevectorILj28EhjiE3endEv
Line
Count
Source
305
3.08M
    const_iterator end() const { return const_iterator(item_ptr(size())); }
_ZNK9prevectorILj16EhjiE3endEv
Line
Count
Source
305
370k
    const_iterator end() const { return const_iterator(item_ptr(size())); }
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
1.71M
    size_t capacity() const {
313
1.71M
        if (is_direct()) {
314
1.67M
            return N;
315
1.67M
        } else {
316
43.7k
            return _union.indirect_contents.capacity;
317
43.7k
        }
318
1.71M
    }
_ZNK9prevectorILj28EhjiE8capacityEv
Line
Count
Source
312
1.63M
    size_t capacity() const {
313
1.63M
        if (is_direct()) {
314
1.59M
            return N;
315
1.59M
        } else {
316
43.7k
            return _union.indirect_contents.capacity;
317
43.7k
        }
318
1.63M
    }
_ZNK9prevectorILj16EhjiE8capacityEv
Line
Count
Source
312
78.8k
    size_t capacity() const {
313
78.8k
        if (is_direct()) {
314
78.8k
            return N;
315
78.8k
        } else {
316
0
            return _union.indirect_contents.capacity;
317
0
        }
318
78.8k
    }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE8capacityEv
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8capacityEv
_ZNK9prevectorILj35EhjiE8capacityEv
Line
Count
Source
312
116
    size_t capacity() const {
313
116
        if (is_direct()) {
314
116
            return N;
315
116
        } else {
316
0
            return _union.indirect_contents.capacity;
317
0
        }
318
116
    }
319
320
586k
    T& operator[](size_type pos) {
321
586k
        return *item_ptr(pos);
322
586k
    }
_ZN9prevectorILj28EhjiEixEj
Line
Count
Source
320
586k
    T& operator[](size_type pos) {
321
586k
        return *item_ptr(pos);
322
586k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiEixEj
Unexecuted instantiation: _ZN9prevectorILj33EhjiEixEj
Unexecuted instantiation: _ZN9prevectorILj16EhjiEixEj
323
324
669k
    const T& operator[](size_type pos) const {
325
669k
        return *item_ptr(pos);
326
669k
    }
_ZNK9prevectorILj28EhjiEixEj
Line
Count
Source
324
512k
    const T& operator[](size_type pos) const {
325
512k
        return *item_ptr(pos);
326
512k
    }
_ZNK9prevectorILj16EhjiEixEj
Line
Count
Source
324
156k
    const T& operator[](size_type pos) const {
325
156k
        return *item_ptr(pos);
326
156k
    }
Unexecuted instantiation: _ZNK9prevectorILj8EijiEixEj
327
328
2.23M
    void resize(size_type new_size) {
329
2.23M
        size_type cur_size = size();
330
2.23M
        if (cur_size == new_size) {
331
1.92M
            return;
332
1.92M
        }
333
307k
        if (cur_size > new_size) {
334
92.3k
            erase(item_ptr(new_size), end());
335
92.3k
            return;
336
92.3k
        }
337
214k
        if (new_size > capacity()) {
338
214k
            change_capacity(new_size);
339
214k
        }
340
214k
        ptrdiff_t increase = new_size - cur_size;
341
214k
        fill(item_ptr(cur_size), increase);
342
214k
        _size += increase;
343
214k
    }
_ZN9prevectorILj28EhjiE6resizeEj
Line
Count
Source
328
2.12M
    void resize(size_type new_size) {
329
2.12M
        size_type cur_size = size();
330
2.12M
        if (cur_size == new_size) {
331
1.90M
            return;
332
1.90M
        }
333
216k
        if (cur_size > new_size) {
334
13.0k
            erase(item_ptr(new_size), end());
335
13.0k
            return;
336
13.0k
        }
337
203k
        if (new_size > capacity()) {
338
203k
            change_capacity(new_size);
339
203k
        }
340
203k
        ptrdiff_t increase = new_size - cur_size;
341
203k
        fill(item_ptr(cur_size), increase);
342
203k
        _size += increase;
343
203k
    }
_ZN9prevectorILj16EhjiE6resizeEj
Line
Count
Source
328
105k
    void resize(size_type new_size) {
329
105k
        size_type cur_size = size();
330
105k
        if (cur_size == new_size) {
331
15.2k
            return;
332
15.2k
        }
333
90.5k
        if (cur_size > new_size) {
334
79.3k
            erase(item_ptr(new_size), end());
335
79.3k
            return;
336
79.3k
        }
337
11.1k
        if (new_size > capacity()) {
338
11.1k
            change_capacity(new_size);
339
11.1k
        }
340
11.1k
        ptrdiff_t increase = new_size - cur_size;
341
11.1k
        fill(item_ptr(cur_size), increase);
342
11.1k
        _size += increase;
343
11.1k
    }
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
953k
    void shrink_to_fit() {
352
953k
        change_capacity(size());
353
953k
    }
_ZN9prevectorILj28EhjiE13shrink_to_fitEv
Line
Count
Source
351
953k
    void shrink_to_fit() {
352
953k
        change_capacity(size());
353
953k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE13shrink_to_fitEv
354
355
1.98M
    void clear() {
356
1.98M
        resize(0);
357
1.98M
    }
_ZN9prevectorILj28EhjiE5clearEv
Line
Count
Source
355
1.92M
    void clear() {
356
1.92M
        resize(0);
357
1.92M
    }
_ZN9prevectorILj16EhjiE5clearEv
Line
Count
Source
355
67.6k
    void clear() {
356
67.6k
        resize(0);
357
67.6k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE5clearEv
Unexecuted instantiation: _ZN9prevectorILj33EhjiE5clearEv
358
359
315k
    iterator insert(iterator pos, const T& value) {
360
315k
        size_type p = pos - begin();
361
315k
        size_type new_size = size() + 1;
362
315k
        if (capacity() < new_size) {
363
0
            change_capacity(new_size + (new_size >> 1));
364
0
        }
365
315k
        T* ptr = item_ptr(p);
366
315k
        T* dst = ptr + 1;
367
315k
        memmove(dst, ptr, (size() - p) * sizeof(T));
368
315k
        _size++;
369
315k
        new(static_cast<void*>(ptr)) T(value);
370
315k
        return iterator(ptr);
371
315k
    }
_ZN9prevectorILj28EhjiE6insertENS0_8iteratorERKh
Line
Count
Source
359
315k
    iterator insert(iterator pos, const T& value) {
360
315k
        size_type p = pos - begin();
361
315k
        size_type new_size = size() + 1;
362
315k
        if (capacity() < new_size) {
363
0
            change_capacity(new_size + (new_size >> 1));
364
0
        }
365
315k
        T* ptr = item_ptr(p);
366
315k
        T* dst = ptr + 1;
367
315k
        memmove(dst, ptr, (size() - p) * sizeof(T));
368
315k
        _size++;
369
315k
        new(static_cast<void*>(ptr)) T(value);
370
315k
        return iterator(ptr);
371
315k
    }
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
205k
    void insert(iterator pos, InputIterator first, InputIterator last) {
388
205k
        size_type p = pos - begin();
389
205k
        difference_type count = last - first;
390
205k
        size_type new_size = size() + count;
391
205k
        if (capacity() < new_size) {
392
87.4k
            change_capacity(new_size + (new_size >> 1));
393
87.4k
        }
394
205k
        T* ptr = item_ptr(p);
395
205k
        T* dst = ptr + count;
396
205k
        memmove(dst, ptr, (size() - p) * sizeof(T));
397
205k
        _size += count;
398
205k
        fill(ptr, first, last);
399
205k
    }
Unexecuted instantiation: _ZN9prevectorILj28EhjiE6insertITkNSt3__114input_iteratorEPKhEEvNS0_8iteratorET_S6_
_ZN9prevectorILj28EhjiE6insertITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvNS0_8iteratorET_S8_
Line
Count
Source
387
205k
    void insert(iterator pos, InputIterator first, InputIterator last) {
388
205k
        size_type p = pos - begin();
389
205k
        difference_type count = last - first;
390
205k
        size_type new_size = size() + count;
391
205k
        if (capacity() < new_size) {
392
87.4k
            change_capacity(new_size + (new_size >> 1));
393
87.4k
        }
394
205k
        T* ptr = item_ptr(p);
395
205k
        T* dst = ptr + count;
396
205k
        memmove(dst, ptr, (size() - p) * sizeof(T));
397
205k
        _size += count;
398
205k
        fill(ptr, first, last);
399
205k
    }
Unexecuted instantiation: _ZN9prevectorILj28EhjiE6insertITkNSt3__114input_iteratorENS0_8iteratorEEEvS3_T_S4_
Unexecuted instantiation: _ZN9prevectorILj8EijiE6insertITkNSt3__114input_iteratorEPiEEvNS0_8iteratorET_S5_
Unexecuted instantiation: _ZN9prevectorILj28EhjiE6insertITkNSt3__114input_iteratorENS2_11__wrap_iterIPhEEEEvNS0_8iteratorET_S7_
_ZN9prevectorILj35EhjiE6insertITkNSt3__114input_iteratorEPhEEvNS0_8iteratorET_S5_
Line
Count
Source
387
58
    void insert(iterator pos, InputIterator first, InputIterator last) {
388
58
        size_type p = pos - begin();
389
58
        difference_type count = last - first;
390
58
        size_type new_size = size() + count;
391
58
        if (capacity() < new_size) {
392
0
            change_capacity(new_size + (new_size >> 1));
393
0
        }
394
58
        T* ptr = item_ptr(p);
395
58
        T* dst = ptr + count;
396
58
        memmove(dst, ptr, (size() - p) * sizeof(T));
397
58
        _size += count;
398
58
        fill(ptr, first, last);
399
58
    }
_ZN9prevectorILj35EhjiE6insertITkNSt3__114input_iteratorEPKhEEvNS0_8iteratorET_S6_
Line
Count
Source
387
58
    void insert(iterator pos, InputIterator first, InputIterator last) {
388
58
        size_type p = pos - begin();
389
58
        difference_type count = last - first;
390
58
        size_type new_size = size() + count;
391
58
        if (capacity() < new_size) {
392
0
            change_capacity(new_size + (new_size >> 1));
393
0
        }
394
58
        T* ptr = item_ptr(p);
395
58
        T* dst = ptr + count;
396
58
        memmove(dst, ptr, (size() - p) * sizeof(T));
397
58
        _size += count;
398
58
        fill(ptr, first, last);
399
58
    }
Unexecuted instantiation: _ZN9prevectorILj28EhjiE6insertITkNSt3__114input_iteratorENS0_14const_iteratorEEEvNS0_8iteratorET_S5_
400
401
367k
    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
367k
        if (capacity() < new_size) {
405
202k
            change_capacity(new_size);
406
202k
            _size += new_size - size();
407
202k
            return;
408
202k
        }
409
165k
        if (new_size < size()) {
410
0
            erase(item_ptr(new_size), end());
411
165k
        } else {
412
165k
            _size += new_size - size();
413
165k
        }
414
165k
    }
_ZN9prevectorILj28EhjiE20resize_uninitializedEj
Line
Count
Source
401
367k
    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
367k
        if (capacity() < new_size) {
405
202k
            change_capacity(new_size);
406
202k
            _size += new_size - size();
407
202k
            return;
408
202k
        }
409
165k
        if (new_size < size()) {
410
0
            erase(item_ptr(new_size), end());
411
165k
        } else {
412
165k
            _size += new_size - size();
413
165k
        }
414
165k
    }
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
92.3k
    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
92.3k
        iterator p = first;
428
92.3k
        char* endp = (char*)&(*end());
429
92.3k
        _size -= last - p;
430
92.3k
        memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
431
92.3k
        return first;
432
92.3k
    }
_ZN9prevectorILj28EhjiE5eraseENS0_8iteratorES1_
Line
Count
Source
420
13.0k
    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
13.0k
        iterator p = first;
428
13.0k
        char* endp = (char*)&(*end());
429
13.0k
        _size -= last - p;
430
13.0k
        memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
431
13.0k
        return first;
432
13.0k
    }
_ZN9prevectorILj16EhjiE5eraseENS0_8iteratorES1_
Line
Count
Source
420
79.3k
    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
79.3k
        iterator p = first;
428
79.3k
        char* endp = (char*)&(*end());
429
79.3k
        _size -= last - p;
430
79.3k
        memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
431
79.3k
        return first;
432
79.3k
    }
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
4.32M
    ~prevector() {
475
4.32M
        if (!is_direct()) {
476
1.65M
            free(_union.indirect_contents.indirect);
477
1.65M
            _union.indirect_contents.indirect = nullptr;
478
1.65M
        }
479
4.32M
    }
_ZN9prevectorILj16EhjiED2Ev
Line
Count
Source
474
486k
    ~prevector() {
475
486k
        if (!is_direct()) {
476
50.6k
            free(_union.indirect_contents.indirect);
477
50.6k
            _union.indirect_contents.indirect = nullptr;
478
50.6k
        }
479
486k
    }
_ZN9prevectorILj28EhjiED2Ev
Line
Count
Source
474
3.83M
    ~prevector() {
475
3.83M
        if (!is_direct()) {
476
1.60M
            free(_union.indirect_contents.indirect);
477
1.60M
            _union.indirect_contents.indirect = nullptr;
478
1.60M
        }
479
3.83M
    }
_ZN9prevectorILj33EhjiED2Ev
Line
Count
Source
474
2.27k
    ~prevector() {
475
2.27k
        if (!is_direct()) {
476
0
            free(_union.indirect_contents.indirect);
477
0
            _union.indirect_contents.indirect = nullptr;
478
0
        }
479
2.27k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiED2Ev
_ZN9prevectorILj35EhjiED2Ev
Line
Count
Source
474
58
    ~prevector() {
475
58
        if (!is_direct()) {
476
0
            free(_union.indirect_contents.indirect);
477
0
            _union.indirect_contents.indirect = nullptr;
478
0
        }
479
58
    }
480
481
99.0k
    bool operator==(const prevector<N, T, Size, Diff>& other) const {
482
99.0k
        if (other.size() != size()) {
483
0
            return false;
484
0
        }
485
99.0k
        const_iterator b1 = begin();
486
99.0k
        const_iterator b2 = other.begin();
487
99.0k
        const_iterator e1 = end();
488
1.97M
        while (b1 != e1) {
489
1.92M
            if ((*b1) != (*b2)) {
490
44.1k
                return false;
491
44.1k
            }
492
1.87M
            ++b1;
493
1.87M
            ++b2;
494
1.87M
        }
495
54.9k
        return true;
496
99.0k
    }
_ZNK9prevectorILj28EhjiEeqERKS0_
Line
Count
Source
481
54.7k
    bool operator==(const prevector<N, T, Size, Diff>& other) const {
482
54.7k
        if (other.size() != size()) {
483
0
            return false;
484
0
        }
485
54.7k
        const_iterator b1 = begin();
486
54.7k
        const_iterator b2 = other.begin();
487
54.7k
        const_iterator e1 = end();
488
1.91M
        while (b1 != e1) {
489
1.86M
            if ((*b1) != (*b2)) {
490
0
                return false;
491
0
            }
492
1.86M
            ++b1;
493
1.86M
            ++b2;
494
1.86M
        }
495
54.7k
        return true;
496
54.7k
    }
Unexecuted instantiation: _ZNK9prevectorILj8EijiEeqERKS0_
_ZNK9prevectorILj16EhjiEeqERKS0_
Line
Count
Source
481
44.3k
    bool operator==(const prevector<N, T, Size, Diff>& other) const {
482
44.3k
        if (other.size() != size()) {
483
0
            return false;
484
0
        }
485
44.3k
        const_iterator b1 = begin();
486
44.3k
        const_iterator b2 = other.begin();
487
44.3k
        const_iterator e1 = end();
488
59.9k
        while (b1 != e1) {
489
59.8k
            if ((*b1) != (*b2)) {
490
44.1k
                return false;
491
44.1k
            }
492
15.6k
            ++b1;
493
15.6k
            ++b2;
494
15.6k
        }
495
160
        return true;
496
44.3k
    }
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
373k
    size_t allocated_memory() const {
526
373k
        if (is_direct()) {
527
17.5k
            return 0;
528
355k
        } else {
529
355k
            return ((size_t)(sizeof(T))) * _union.indirect_contents.capacity;
530
355k
        }
531
373k
    }
532
533
234k
    value_type* data() {
534
234k
        return item_ptr(0);
535
234k
    }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE4dataEv
_ZN9prevectorILj28EhjiE4dataEv
Line
Count
Source
533
196k
    value_type* data() {
534
196k
        return item_ptr(0);
535
196k
    }
_ZN9prevectorILj16EhjiE4dataEv
Line
Count
Source
533
38.1k
    value_type* data() {
534
38.1k
        return item_ptr(0);
535
38.1k
    }
_ZN9prevectorILj35EhjiE4dataEv
Line
Count
Source
533
58
    value_type* data() {
534
58
        return item_ptr(0);
535
58
    }
536
537
3.92M
    const value_type* data() const {
538
3.92M
        return item_ptr(0);
539
3.92M
    }
_ZNK9prevectorILj28EhjiE4dataEv
Line
Count
Source
537
3.60M
    const value_type* data() const {
538
3.60M
        return item_ptr(0);
539
3.60M
    }
_ZNK9prevectorILj16EhjiE4dataEv
Line
Count
Source
537
321k
    const value_type* data() const {
538
321k
        return item_ptr(0);
539
321k
    }
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE4dataEv
540
};
541
542
#endif // BITCOIN_PREVECTOR_H