fuzz coverage

Coverage Report

Created: 2025-09-17 22:41

/Users/eugenesiegel/btc/bitcoin/src/prevector.h
Line
Count
Source (jump to first uncovered line)
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
30.7M
        iterator(T* ptr_) : ptr(ptr_) {}
_ZN9prevectorILj16EhjiE8iteratorC2EPh
Line
Count
Source
60
1.13M
        iterator(T* ptr_) : ptr(ptr_) {}
_ZN9prevectorILj36EhjiE8iteratorC2EPh
Line
Count
Source
60
29.6M
        iterator(T* ptr_) : ptr(ptr_) {}
Unexecuted instantiation: _ZN9prevectorILj8EijiE8iteratorC2EPi
Unexecuted instantiation: _ZN9prevectorILj33EhjiE8iteratorC2EPh
_ZN9prevectorILj35EhjiE8iteratorC2EPh
Line
Count
Source
60
1.10k
        iterator(T* ptr_) : ptr(ptr_) {}
61
27.1M
        T& operator*() const { return *ptr; }
_ZNK9prevectorILj36EhjiE8iteratordeEv
Line
Count
Source
61
24.8M
        T& operator*() const { return *ptr; }
_ZNK9prevectorILj16EhjiE8iteratordeEv
Line
Count
Source
61
2.27M
        T& operator*() const { return *ptr; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE8iteratordeEv
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8iteratordeEv
_ZNK9prevectorILj35EhjiE8iteratordeEv
Line
Count
Source
61
1.10k
        T& operator*() const { return *ptr; }
62
3.61M
        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
11.5M
        difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }
_ZmiN9prevectorILj36EhjiE8iteratorES1_
Line
Count
Source
68
11.1M
        difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }
_ZmiN9prevectorILj16EhjiE8iteratorES1_
Line
Count
Source
68
378k
        difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }
Unexecuted instantiation: _ZmiN9prevectorILj8EijiE8iteratorES1_
Unexecuted instantiation: _ZmiN9prevectorILj33EhjiE8iteratorES1_
_ZmiN9prevectorILj35EhjiE8iteratorES1_
Line
Count
Source
68
550
        difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }
69
0
        iterator operator+(size_type n) const { return iterator(ptr + n); }
Unexecuted instantiation: _ZNK9prevectorILj36EhjiE8iteratorplEj
Unexecuted instantiation: _ZNK9prevectorILj8EijiE8iteratorplEj
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8iteratorplEj
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
136M
        const_iterator(const T* ptr_) : ptr(ptr_) {}
_ZN9prevectorILj16EhjiE14const_iteratorC2EPKh
Line
Count
Source
91
4.50M
        const_iterator(const T* ptr_) : ptr(ptr_) {}
_ZN9prevectorILj36EhjiE14const_iteratorC2EPKh
Line
Count
Source
91
132M
        const_iterator(const T* ptr_) : ptr(ptr_) {}
Unexecuted instantiation: _ZN9prevectorILj8EijiE14const_iteratorC2EPKi
92
0
        const_iterator(iterator x) : ptr(&(*x)) {}
93
907M
        const T& operator*() const { return *ptr; }
_ZNK9prevectorILj36EhjiE14const_iteratordeEv
Line
Count
Source
93
882M
        const T& operator*() const { return *ptr; }
_ZNK9prevectorILj16EhjiE14const_iteratordeEv
Line
Count
Source
93
24.5M
        const T& operator*() const { return *ptr; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratordeEv
94
11.1M
        const T* operator->() const { return ptr; }
_ZNK9prevectorILj16EhjiE14const_iteratorptEv
Line
Count
Source
94
1.07M
        const T* operator->() const { return ptr; }
_ZNK9prevectorILj36EhjiE14const_iteratorptEv
Line
Count
Source
94
10.0M
        const T* operator->() const { return ptr; }
95
0
        const T& operator[](size_type pos) const { return ptr[pos]; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratorixEj
Unexecuted instantiation: _ZNK9prevectorILj36EhjiE14const_iteratorixEj
96
835M
        const_iterator& operator++() { ptr++; return *this; }
_ZN9prevectorILj36EhjiE14const_iteratorppEv
Line
Count
Source
96
810M
        const_iterator& operator++() { ptr++; return *this; }
_ZN9prevectorILj16EhjiE14const_iteratorppEv
Line
Count
Source
96
24.1M
        const_iterator& operator++() { ptr++; return *this; }
Unexecuted instantiation: _ZN9prevectorILj8EijiE14const_iteratorppEv
97
0
        const_iterator& operator--() { ptr--; return *this; }
98
7.96M
        const_iterator operator++(int) { const_iterator copy(*this); ++(*this); return copy; }
99
        const_iterator operator--(int) { const_iterator copy(*this); --(*this); return copy; }
100
33.6M
        difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); }
_ZmiN9prevectorILj16EhjiE14const_iteratorES1_
Line
Count
Source
100
143k
        difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); }
_ZmiN9prevectorILj36EhjiE14const_iteratorES1_
Line
Count
Source
100
33.5M
        difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); }
Unexecuted instantiation: _ZmiN9prevectorILj8EijiE14const_iteratorES1_
101
5.22M
        const_iterator operator+(size_type n) const { return const_iterator(ptr + n); }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratorplEj
_ZNK9prevectorILj36EhjiE14const_iteratorplEj
Line
Count
Source
101
5.22M
        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
5.91M
        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: _ZNK9prevectorILj8EijiE14const_iteratormiEj
Unexecuted instantiation: _ZNK9prevectorILj36EhjiE14const_iteratormiEj
105
        const_iterator& operator-=(size_type n) { ptr -= n; return *this; }
106
0
        bool operator==(const_iterator x) const { return ptr == x.ptr; }
107
852M
        bool operator!=(const_iterator x) const { return ptr != x.ptr; }
_ZNK9prevectorILj36EhjiE14const_iteratorneES1_
Line
Count
Source
107
827M
        bool operator!=(const_iterator x) const { return ptr != x.ptr; }
_ZNK9prevectorILj16EhjiE14const_iteratorneES1_
Line
Count
Source
107
25.7M
        bool operator!=(const_iterator x) const { return ptr != x.ptr; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE14const_iteratorneES1_
108
7.96M
        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
14.8M
        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
88.5M
    T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
_ZN9prevectorILj36EhjiE10direct_ptrEi
Line
Count
Source
130
84.4M
    T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE10direct_ptrEi
_ZN9prevectorILj16EhjiE10direct_ptrEi
Line
Count
Source
130
4.08M
    T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
Unexecuted instantiation: _ZN9prevectorILj8EijiE10direct_ptrEi
_ZN9prevectorILj35EhjiE10direct_ptrEi
Line
Count
Source
130
2.20k
    T* direct_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.direct) + pos; }
131
179M
    const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; }
_ZNK9prevectorILj36EhjiE10direct_ptrEi
Line
Count
Source
131
173M
    const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; }
_ZNK9prevectorILj16EhjiE10direct_ptrEi
Line
Count
Source
131
6.53M
    const T* direct_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.direct) + pos; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE10direct_ptrEi
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE10direct_ptrEi
132
24.2M
    T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; }
_ZN9prevectorILj36EhjiE12indirect_ptrEi
Line
Count
Source
132
23.8M
    T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE12indirect_ptrEi
_ZN9prevectorILj16EhjiE12indirect_ptrEi
Line
Count
Source
132
382k
    T* indirect_ptr(difference_type pos) { return reinterpret_cast<T*>(_union.indirect_contents.indirect) + pos; }
Unexecuted instantiation: _ZN9prevectorILj8EijiE12indirect_ptrEi
Unexecuted instantiation: _ZN9prevectorILj35EhjiE12indirect_ptrEi
133
38.9M
    const T* indirect_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.indirect_contents.indirect) + pos; }
_ZNK9prevectorILj36EhjiE12indirect_ptrEi
Line
Count
Source
133
38.3M
    const T* indirect_ptr(difference_type pos) const { return reinterpret_cast<const T*>(_union.indirect_contents.indirect) + pos; }
_ZNK9prevectorILj16EhjiE12indirect_ptrEi
Line
Count
Source
133
577k
    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
134
987M
    bool is_direct() const { return _size <= N; }
_ZNK9prevectorILj36EhjiE9is_directEv
Line
Count
Source
134
963M
    bool is_direct() const { return _size <= N; }
_ZNK9prevectorILj33EhjiE9is_directEv
Line
Count
Source
134
52.9k
    bool is_direct() const { return _size <= N; }
_ZNK9prevectorILj16EhjiE9is_directEv
Line
Count
Source
134
24.1M
    bool is_direct() const { return _size <= N; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE9is_directEv
_ZNK9prevectorILj35EhjiE9is_directEv
Line
Count
Source
134
5.22k
    bool is_direct() const { return _size <= N; }
135
136
62.0M
    void change_capacity(size_type new_capacity) {
137
62.0M
        if (new_capacity <= N) {
138
52.9M
            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
52.9M
        } else {
147
9.10M
            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
9.10M
            } else {
155
9.10M
                char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
156
9.10M
                assert(new_indirect);
157
9.10M
                T* src = direct_ptr(0);
158
9.10M
                T* dst = reinterpret_cast<T*>(new_indirect);
159
9.10M
                memcpy(dst, src, size() * sizeof(T));
160
9.10M
                _union.indirect_contents.indirect = new_indirect;
161
9.10M
                _union.indirect_contents.capacity = new_capacity;
162
9.10M
                _size += N + 1;
163
9.10M
            }
164
9.10M
        }
165
62.0M
    }
_ZN9prevectorILj36EhjiE15change_capacityEj
Line
Count
Source
136
59.4M
    void change_capacity(size_type new_capacity) {
137
59.4M
        if (new_capacity <= N) {
138
50.7M
            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
50.7M
        } else {
147
8.79M
            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
8.79M
            } else {
155
8.79M
                char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
156
8.79M
                assert(new_indirect);
157
8.79M
                T* src = direct_ptr(0);
158
8.79M
                T* dst = reinterpret_cast<T*>(new_indirect);
159
8.79M
                memcpy(dst, src, size() * sizeof(T));
160
8.79M
                _union.indirect_contents.indirect = new_indirect;
161
8.79M
                _union.indirect_contents.capacity = new_capacity;
162
8.79M
                _size += N + 1;
163
8.79M
            }
164
8.79M
        }
165
59.4M
    }
_ZN9prevectorILj16EhjiE15change_capacityEj
Line
Count
Source
136
2.52M
    void change_capacity(size_type new_capacity) {
137
2.52M
        if (new_capacity <= N) {
138
2.21M
            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
2.21M
        } else {
147
312k
            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
312k
            } else {
155
312k
                char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
156
312k
                assert(new_indirect);
157
312k
                T* src = direct_ptr(0);
158
312k
                T* dst = reinterpret_cast<T*>(new_indirect);
159
312k
                memcpy(dst, src, size() * sizeof(T));
160
312k
                _union.indirect_contents.indirect = new_indirect;
161
312k
                _union.indirect_contents.capacity = new_capacity;
162
312k
                _size += N + 1;
163
312k
            }
164
312k
        }
165
2.52M
    }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE15change_capacityEj
Unexecuted instantiation: _ZN9prevectorILj8EijiE15change_capacityEj
_ZN9prevectorILj35EhjiE15change_capacityEj
Line
Count
Source
136
275
    void change_capacity(size_type new_capacity) {
137
275
        if (new_capacity <= N) {
138
275
            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
275
        } else {
147
0
            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
0
            } else {
155
0
                char* new_indirect = static_cast<char*>(malloc(((size_t)sizeof(T)) * new_capacity));
156
0
                assert(new_indirect);
157
0
                T* src = direct_ptr(0);
158
0
                T* dst = reinterpret_cast<T*>(new_indirect);
159
0
                memcpy(dst, src, size() * sizeof(T));
160
0
                _union.indirect_contents.indirect = new_indirect;
161
0
                _union.indirect_contents.capacity = new_capacity;
162
0
                _size += N + 1;
163
0
            }
164
0
        }
165
275
    }
166
167
103M
    T* item_ptr(difference_type pos) { return is_direct() ? 
direct_ptr(pos)79.4M
:
indirect_ptr(pos)24.2M
; }
_ZN9prevectorILj36EhjiE8item_ptrEi
Line
Count
Source
167
99.5M
    T* item_ptr(difference_type pos) { return is_direct() ? 
direct_ptr(pos)75.6M
:
indirect_ptr(pos)23.8M
; }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE8item_ptrEi
_ZN9prevectorILj16EhjiE8item_ptrEi
Line
Count
Source
167
4.15M
    T* item_ptr(difference_type pos) { return is_direct() ? 
direct_ptr(pos)3.77M
:
indirect_ptr(pos)382k
; }
Unexecuted instantiation: _ZN9prevectorILj8EijiE8item_ptrEi
_ZN9prevectorILj35EhjiE8item_ptrEi
Line
Count
Source
167
2.20k
    T* item_ptr(difference_type pos) { return is_direct() ? direct_ptr(pos) : 
indirect_ptr(pos)0
; }
168
218M
    const T* item_ptr(difference_type pos) const { return is_direct() ? 
direct_ptr(pos)179M
:
indirect_ptr(pos)38.9M
; }
_ZNK9prevectorILj36EhjiE8item_ptrEi
Line
Count
Source
168
211M
    const T* item_ptr(difference_type pos) const { return is_direct() ? 
direct_ptr(pos)173M
:
indirect_ptr(pos)38.3M
; }
_ZNK9prevectorILj16EhjiE8item_ptrEi
Line
Count
Source
168
7.11M
    const T* item_ptr(difference_type pos) const { return is_direct() ? 
direct_ptr(pos)6.53M
:
indirect_ptr(pos)577k
; }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE8item_ptrEi
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8item_ptrEi
169
170
3.22M
    void fill(T* dst, ptrdiff_t count, const T& value = T{}) {
171
3.22M
        std::fill_n(dst, count, value);
172
3.22M
    }
_ZN9prevectorILj36EhjiE4fillEPhlRKh
Line
Count
Source
170
2.15M
    void fill(T* dst, ptrdiff_t count, const T& value = T{}) {
171
2.15M
        std::fill_n(dst, count, value);
172
2.15M
    }
_ZN9prevectorILj16EhjiE4fillEPhlRKh
Line
Count
Source
170
1.06M
    void fill(T* dst, ptrdiff_t count, const T& value = T{}) {
171
1.06M
        std::fill_n(dst, count, value);
172
1.06M
    }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE4fillEPhlRKh
Unexecuted instantiation: _ZN9prevectorILj8EijiE4fillEPilRKi
173
174
    template <std::input_iterator InputIterator>
175
47.3M
    void fill(T* dst, InputIterator first, InputIterator last) {
176
875M
        while (first != last) {
177
828M
            new(static_cast<void*>(dst)) T(*first);
178
828M
            ++dst;
179
828M
            ++first;
180
828M
        }
181
47.3M
    }
Unexecuted instantiation: _ZN9prevectorILj36EhjiE4fillITkNSt3__114input_iteratorEPKhEEvPhT_S6_
_ZN9prevectorILj36EhjiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvPhT_S8_
Line
Count
Source
175
3.75M
    void fill(T* dst, InputIterator first, InputIterator last) {
176
39.8M
        while (first != last) {
177
36.0M
            new(static_cast<void*>(dst)) T(*first);
178
36.0M
            ++dst;
179
36.0M
            ++first;
180
36.0M
        }
181
3.75M
    }
_ZN9prevectorILj36EhjiE4fillITkNSt3__114input_iteratorENS0_14const_iteratorEEEvPhT_S5_
Line
Count
Source
175
41.8M
    void fill(T* dst, InputIterator first, InputIterator last) {
176
808M
        while (first != last) {
177
766M
            new(static_cast<void*>(dst)) T(*first);
178
766M
            ++dst;
179
766M
            ++first;
180
766M
        }
181
41.8M
    }
_ZN9prevectorILj16EhjiE4fillITkNSt3__114input_iteratorENS0_14const_iteratorEEEvPhT_S5_
Line
Count
Source
175
1.60M
    void fill(T* dst, InputIterator first, InputIterator last) {
176
25.6M
        while (first != last) {
177
24.0M
            new(static_cast<void*>(dst)) T(*first);
178
24.0M
            ++dst;
179
24.0M
            ++first;
180
24.0M
        }
181
1.60M
    }
Unexecuted instantiation: _ZN9prevectorILj36EhjiE4fillITkNSt3__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: _ZN9prevectorILj36EhjiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPhEEEEvS4_T_S6_
_ZN9prevectorILj16EhjiE4fillITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvPhT_S8_
Line
Count
Source
175
115k
    void fill(T* dst, InputIterator first, InputIterator last) {
176
1.97M
        while (first != last) {
177
1.85M
            new(static_cast<void*>(dst)) T(*first);
178
1.85M
            ++dst;
179
1.85M
            ++first;
180
1.85M
        }
181
115k
    }
_ZN9prevectorILj16EhjiE4fillITkNSt3__114input_iteratorEPhEEvS3_T_S4_
Line
Count
Source
175
4.29k
    void fill(T* dst, InputIterator first, InputIterator last) {
176
47.2k
        while (first != last) {
177
42.9k
            new(static_cast<void*>(dst)) T(*first);
178
42.9k
            ++dst;
179
42.9k
            ++first;
180
42.9k
        }
181
4.29k
    }
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
175
275
    void fill(T* dst, InputIterator first, InputIterator last) {
176
9.07k
        while (first != last) {
177
8.80k
            new(static_cast<void*>(dst)) T(*first);
178
8.80k
            ++dst;
179
8.80k
            ++first;
180
8.80k
        }
181
275
    }
_ZN9prevectorILj35EhjiE4fillITkNSt3__114input_iteratorEPhEEvS3_T_S4_
Line
Count
Source
175
275
    void fill(T* dst, InputIterator first, InputIterator last) {
176
825
        while (first != last) {
177
550
            new(static_cast<void*>(dst)) T(*first);
178
550
            ++dst;
179
550
            ++first;
180
550
        }
181
275
    }
_ZN9prevectorILj35EhjiE4fillITkNSt3__114input_iteratorEPKhEEvPhT_S6_
Line
Count
Source
175
275
    void fill(T* dst, InputIterator first, InputIterator last) {
176
550
        while (first != last) {
177
275
            new(static_cast<void*>(dst)) T(*first);
178
275
            ++dst;
179
275
            ++first;
180
275
        }
181
275
    }
182
183
public:
184
162
    void assign(size_type n, const T& val) {
185
162
        clear();
186
162
        if (capacity() < n) {
187
0
            change_capacity(n);
188
0
        }
189
162
        _size += n;
190
162
        fill(item_ptr(0), n, val);
191
162
    }
_ZN9prevectorILj16EhjiE6assignEjRKh
Line
Count
Source
184
162
    void assign(size_type n, const T& val) {
185
162
        clear();
186
162
        if (capacity() < n) {
187
0
            change_capacity(n);
188
0
        }
189
162
        _size += n;
190
162
        fill(item_ptr(0), n, val);
191
162
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE6assignEjRKi
192
193
    template <std::input_iterator InputIterator>
194
9.35M
    void assign(InputIterator first, InputIterator last) {
195
9.35M
        size_type n = last - first;
196
9.35M
        clear();
197
9.35M
        if (capacity() < n) {
198
428k
            change_capacity(n);
199
428k
        }
200
9.35M
        _size += n;
201
9.35M
        fill(item_ptr(0), first, last);
202
9.35M
    }
_ZN9prevectorILj16EhjiE6assignITkNSt3__114input_iteratorENS0_14const_iteratorEEEvT_S4_
Line
Count
Source
194
142k
    void assign(InputIterator first, InputIterator last) {
195
142k
        size_type n = last - first;
196
142k
        clear();
197
142k
        if (capacity() < n) {
198
139
            change_capacity(n);
199
139
        }
200
142k
        _size += n;
201
142k
        fill(item_ptr(0), first, last);
202
142k
    }
_ZN9prevectorILj36EhjiE6assignITkNSt3__114input_iteratorENS0_14const_iteratorEEEvT_S4_
Line
Count
Source
194
9.09M
    void assign(InputIterator first, InputIterator last) {
195
9.09M
        size_type n = last - first;
196
9.09M
        clear();
197
9.09M
        if (capacity() < n) {
198
427k
            change_capacity(n);
199
427k
        }
200
9.09M
        _size += n;
201
9.09M
        fill(item_ptr(0), first, last);
202
9.09M
    }
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
194
115k
    void assign(InputIterator first, InputIterator last) {
195
115k
        size_type n = last - first;
196
115k
        clear();
197
115k
        if (capacity() < n) {
198
0
            change_capacity(n);
199
0
        }
200
115k
        _size += n;
201
115k
        fill(item_ptr(0), first, last);
202
115k
    }
_ZN9prevectorILj16EhjiE6assignITkNSt3__114input_iteratorEPhEEvT_S4_
Line
Count
Source
194
4.29k
    void assign(InputIterator first, InputIterator last) {
195
4.29k
        size_type n = last - first;
196
4.29k
        clear();
197
4.29k
        if (capacity() < n) {
198
0
            change_capacity(n);
199
0
        }
200
4.29k
        _size += n;
201
4.29k
        fill(item_ptr(0), first, last);
202
4.29k
    }
Unexecuted instantiation: _ZN9prevectorILj16EhjiE6assignITkNSt3__114input_iteratorENS2_11__wrap_iterIPhEEEEvT_S6_
Unexecuted instantiation: _ZN9prevectorILj16EhjiE6assignITkNSt3__114input_iteratorEPKhEEvT_S5_
203
204
38.1M
    prevector() = default;
_ZN9prevectorILj36EhjiEC2Ev
Line
Count
Source
204
38.0M
    prevector() = default;
_ZN9prevectorILj33EhjiEC2Ev
Line
Count
Source
204
52.9k
    prevector() = default;
Unexecuted instantiation: _ZN9prevectorILj8EijiEC2Ev
205
206
    explicit prevector(size_type n) {
207
        resize(n);
208
    }
209
210
993k
    explicit prevector(size_type n, const T& val) {
211
993k
        change_capacity(n);
212
993k
        _size += n;
213
993k
        fill(item_ptr(0), n, val);
214
993k
    }
Unexecuted instantiation: _ZN9prevectorILj33EhjiEC2EjRKh
_ZN9prevectorILj16EhjiEC2EjRKh
Line
Count
Source
210
993k
    explicit prevector(size_type n, const T& val) {
211
993k
        change_capacity(n);
212
993k
        _size += n;
213
993k
        fill(item_ptr(0), n, val);
214
993k
    }
215
216
    template <std::input_iterator InputIterator>
217
1.01M
    prevector(InputIterator first, InputIterator last) {
218
1.01M
        size_type n = last - first;
219
1.01M
        change_capacity(n);
220
1.01M
        _size += n;
221
1.01M
        fill(item_ptr(0), first, last);
222
1.01M
    }
_ZN9prevectorILj36EhjiEC2ITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEET_S7_
Line
Count
Source
217
1.01M
    prevector(InputIterator first, InputIterator last) {
218
1.01M
        size_type n = last - first;
219
1.01M
        change_capacity(n);
220
1.01M
        _size += n;
221
1.01M
        fill(item_ptr(0), first, last);
222
1.01M
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiEC2ITkNSt3__114input_iteratorENS2_11__wrap_iterIPKiEEEET_S7_
Unexecuted instantiation: _ZN9prevectorILj8EijiEC2ITkNSt3__114input_iteratorENS0_14const_iteratorEEET_S4_
Unexecuted instantiation: _ZN9prevectorILj36EhjiEC2ITkNSt3__114input_iteratorENS2_11__wrap_iterIPhEEEET_S6_
_ZN9prevectorILj35EhjiEC2ITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEET_S7_
Line
Count
Source
217
275
    prevector(InputIterator first, InputIterator last) {
218
275
        size_type n = last - first;
219
275
        change_capacity(n);
220
275
        _size += n;
221
275
        fill(item_ptr(0), first, last);
222
275
    }
Unexecuted instantiation: _ZN9prevectorILj36EhjiEC2ITkNSt3__114input_iteratorENS0_14const_iteratorEEET_S4_
223
224
34.2M
    prevector(const prevector<N, T, Size, Diff>& other) {
225
34.2M
        size_type n = other.size();
226
34.2M
        change_capacity(n);
227
34.2M
        _size += n;
228
34.2M
        fill(item_ptr(0), other.begin(),  other.end());
229
34.2M
    }
_ZN9prevectorILj16EhjiEC2ERKS0_
Line
Count
Source
224
1.46M
    prevector(const prevector<N, T, Size, Diff>& other) {
225
1.46M
        size_type n = other.size();
226
1.46M
        change_capacity(n);
227
1.46M
        _size += n;
228
1.46M
        fill(item_ptr(0), other.begin(),  other.end());
229
1.46M
    }
_ZN9prevectorILj36EhjiEC2ERKS0_
Line
Count
Source
224
32.7M
    prevector(const prevector<N, T, Size, Diff>& other) {
225
32.7M
        size_type n = other.size();
226
32.7M
        change_capacity(n);
227
32.7M
        _size += n;
228
32.7M
        fill(item_ptr(0), other.begin(),  other.end());
229
32.7M
    }
230
231
    prevector(prevector<N, T, Size, Diff>&& other) noexcept
232
7.68M
        : _union(std::move(other._union)), _size(other._size)
233
7.68M
    {
234
7.68M
        other._size = 0;
235
7.68M
    }
_ZN9prevectorILj16EhjiEC2EOS0_
Line
Count
Source
232
53.8k
        : _union(std::move(other._union)), _size(other._size)
233
53.8k
    {
234
53.8k
        other._size = 0;
235
53.8k
    }
_ZN9prevectorILj36EhjiEC2EOS0_
Line
Count
Source
232
7.62M
        : _union(std::move(other._union)), _size(other._size)
233
7.62M
    {
234
7.62M
        other._size = 0;
235
7.62M
    }
236
237
9.23M
    prevector& operator=(const prevector<N, T, Size, Diff>& other) {
238
9.23M
        if (&other == this) {
239
0
            return *this;
240
0
        }
241
9.23M
        assign(other.begin(), other.end());
242
9.23M
        return *this;
243
9.23M
    }
_ZN9prevectorILj16EhjiEaSERKS0_
Line
Count
Source
237
142k
    prevector& operator=(const prevector<N, T, Size, Diff>& other) {
238
142k
        if (&other == this) {
239
0
            return *this;
240
0
        }
241
142k
        assign(other.begin(), other.end());
242
142k
        return *this;
243
142k
    }
_ZN9prevectorILj36EhjiEaSERKS0_
Line
Count
Source
237
9.09M
    prevector& operator=(const prevector<N, T, Size, Diff>& other) {
238
9.09M
        if (&other == this) {
239
0
            return *this;
240
0
        }
241
9.09M
        assign(other.begin(), other.end());
242
9.09M
        return *this;
243
9.09M
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiEaSERKS0_
244
245
5.50M
    prevector& operator=(prevector<N, T, Size, Diff>&& other) noexcept {
246
5.50M
        if (!is_direct()) {
247
0
            free(_union.indirect_contents.indirect);
248
0
        }
249
5.50M
        _union = std::move(other._union);
250
5.50M
        _size = other._size;
251
5.50M
        other._size = 0;
252
5.50M
        return *this;
253
5.50M
    }
Unexecuted instantiation: _ZN9prevectorILj16EhjiEaSEOS0_
_ZN9prevectorILj36EhjiEaSEOS0_
Line
Count
Source
245
5.50M
    prevector& operator=(prevector<N, T, Size, Diff>&& other) noexcept {
246
5.50M
        if (!is_direct()) {
247
0
            free(_union.indirect_contents.indirect);
248
0
        }
249
5.50M
        _union = std::move(other._union);
250
5.50M
        _size = other._size;
251
5.50M
        other._size = 0;
252
5.50M
        return *this;
253
5.50M
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiEaSEOS0_
254
255
476M
    size_type size() const {
256
476M
        return is_direct() ? 
_size412M
:
_size - N - 164.0M
;
257
476M
    }
_ZNK9prevectorILj36EhjiE4sizeEv
Line
Count
Source
255
469M
    size_type size() const {
256
469M
        return is_direct() ? 
_size406M
:
_size - N - 163.3M
;
257
469M
    }
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE4sizeEv
_ZNK9prevectorILj16EhjiE4sizeEv
Line
Count
Source
255
7.50M
    size_type size() const {
256
7.50M
        return is_direct() ? 
_size6.85M
:
_size - N - 1647k
;
257
7.50M
    }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE4sizeEv
_ZNK9prevectorILj35EhjiE4sizeEv
Line
Count
Source
255
1.92k
    size_type size() const {
256
1.92k
        return is_direct() ? _size : 
_size - N - 10
;
257
1.92k
    }
258
259
77.1M
    bool empty() const {
260
77.1M
        return size() == 0;
261
77.1M
    }
_ZNK9prevectorILj36EhjiE5emptyEv
Line
Count
Source
259
77.1M
    bool empty() const {
260
77.1M
        return size() == 0;
261
77.1M
    }
Unexecuted instantiation: _ZNK9prevectorILj16EhjiE5emptyEv
Unexecuted instantiation: _ZNK9prevectorILj8EijiE5emptyEv
262
263
10.7M
    iterator begin() { return iterator(item_ptr(0)); }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE5beginEv
_ZN9prevectorILj36EhjiE5beginEv
Line
Count
Source
263
10.7M
    iterator begin() { return iterator(item_ptr(0)); }
Unexecuted instantiation: _ZN9prevectorILj16EhjiE5beginEv
Unexecuted instantiation: _ZN9prevectorILj8EijiE5beginEv
_ZN9prevectorILj35EhjiE5beginEv
Line
Count
Source
263
550
    iterator begin() { return iterator(item_ptr(0)); }
264
62.9M
    const_iterator begin() const { return const_iterator(item_ptr(0)); }
_ZNK9prevectorILj36EhjiE5beginEv
Line
Count
Source
264
60.0M
    const_iterator begin() const { return const_iterator(item_ptr(0)); }
_ZNK9prevectorILj16EhjiE5beginEv
Line
Count
Source
264
2.82M
    const_iterator begin() const { return const_iterator(item_ptr(0)); }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE5beginEv
265
12.7M
    iterator end() { return iterator(item_ptr(size())); }
_ZN9prevectorILj36EhjiE3endEv
Line
Count
Source
265
12.0M
    iterator end() { return iterator(item_ptr(size())); }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE3endEv
_ZN9prevectorILj16EhjiE3endEv
Line
Count
Source
265
757k
    iterator end() { return iterator(item_ptr(size())); }
Unexecuted instantiation: _ZN9prevectorILj8EijiE3endEv
_ZN9prevectorILj35EhjiE3endEv
Line
Count
Source
265
550
    iterator end() { return iterator(item_ptr(size())); }
266
68.5M
    const_iterator end() const { return const_iterator(item_ptr(size())); }
_ZNK9prevectorILj36EhjiE3endEv
Line
Count
Source
266
66.8M
    const_iterator end() const { return const_iterator(item_ptr(size())); }
_ZNK9prevectorILj16EhjiE3endEv
Line
Count
Source
266
1.67M
    const_iterator end() const { return const_iterator(item_ptr(size())); }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE3endEv
267
268
29.9M
    size_t capacity() const {
269
29.9M
        if (is_direct()) {
270
29.7M
            return N;
271
29.7M
        } else {
272
194k
            return _union.indirect_contents.capacity;
273
194k
        }
274
29.9M
    }
_ZNK9prevectorILj36EhjiE8capacityEv
Line
Count
Source
268
29.6M
    size_t capacity() const {
269
29.6M
        if (is_direct()) {
270
29.4M
            return N;
271
29.4M
        } else {
272
194k
            return _union.indirect_contents.capacity;
273
194k
        }
274
29.6M
    }
_ZNK9prevectorILj16EhjiE8capacityEv
Line
Count
Source
268
332k
    size_t capacity() const {
269
332k
        if (is_direct()) {
270
332k
            return N;
271
332k
        } else {
272
0
            return _union.indirect_contents.capacity;
273
0
        }
274
332k
    }
Unexecuted instantiation: _ZNK9prevectorILj8EijiE8capacityEv
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE8capacityEv
_ZNK9prevectorILj35EhjiE8capacityEv
Line
Count
Source
268
550
    size_t capacity() const {
269
550
        if (is_direct()) {
270
550
            return N;
271
550
        } else {
272
0
            return _union.indirect_contents.capacity;
273
0
        }
274
550
    }
275
276
20.9M
    T& operator[](size_type pos) {
277
20.9M
        return *item_ptr(pos);
278
20.9M
    }
_ZN9prevectorILj36EhjiEixEj
Line
Count
Source
276
20.9M
    T& operator[](size_type pos) {
277
20.9M
        return *item_ptr(pos);
278
20.9M
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiEixEj
Unexecuted instantiation: _ZN9prevectorILj33EhjiEixEj
Unexecuted instantiation: _ZN9prevectorILj16EhjiEixEj
279
280
22.5M
    const T& operator[](size_type pos) const {
281
22.5M
        return *item_ptr(pos);
282
22.5M
    }
_ZNK9prevectorILj36EhjiEixEj
Line
Count
Source
280
21.3M
    const T& operator[](size_type pos) const {
281
21.3M
        return *item_ptr(pos);
282
21.3M
    }
_ZNK9prevectorILj16EhjiEixEj
Line
Count
Source
280
1.24M
    const T& operator[](size_type pos) const {
281
1.24M
        return *item_ptr(pos);
282
1.24M
    }
Unexecuted instantiation: _ZNK9prevectorILj8EijiEixEj
283
284
42.9M
    void resize(size_type new_size) {
285
42.9M
        size_type cur_size = size();
286
42.9M
        if (cur_size == new_size) {
287
39.7M
            return;
288
39.7M
        }
289
3.22M
        if (cur_size > new_size) {
290
993k
            erase(item_ptr(new_size), end());
291
993k
            return;
292
993k
        }
293
2.22M
        if (new_size > capacity()) {
294
1.67M
            change_capacity(new_size);
295
1.67M
        }
296
2.22M
        ptrdiff_t increase = new_size - cur_size;
297
2.22M
        fill(item_ptr(cur_size), increase);
298
2.22M
        _size += increase;
299
2.22M
    }
_ZN9prevectorILj36EhjiE6resizeEj
Line
Count
Source
284
42.4M
    void resize(size_type new_size) {
285
42.4M
        size_type cur_size = size();
286
42.4M
        if (cur_size == new_size) {
287
39.6M
            return;
288
39.6M
        }
289
2.77M
        if (cur_size > new_size) {
290
614k
            erase(item_ptr(new_size), end());
291
614k
            return;
292
614k
        }
293
2.15M
        if (new_size > capacity()) {
294
1.60M
            change_capacity(new_size);
295
1.60M
        }
296
2.15M
        ptrdiff_t increase = new_size - cur_size;
297
2.15M
        fill(item_ptr(cur_size), increase);
298
2.15M
        _size += increase;
299
2.15M
    }
_ZN9prevectorILj16EhjiE6resizeEj
Line
Count
Source
284
492k
    void resize(size_type new_size) {
285
492k
        size_type cur_size = size();
286
492k
        if (cur_size == new_size) {
287
43.5k
            return;
288
43.5k
        }
289
448k
        if (cur_size > new_size) {
290
378k
            erase(item_ptr(new_size), end());
291
378k
            return;
292
378k
        }
293
69.8k
        if (new_size > capacity()) {
294
69.8k
            change_capacity(new_size);
295
69.8k
        }
296
69.8k
        ptrdiff_t increase = new_size - cur_size;
297
69.8k
        fill(item_ptr(cur_size), increase);
298
69.8k
        _size += increase;
299
69.8k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE6resizeEj
Unexecuted instantiation: _ZN9prevectorILj33EhjiE6resizeEj
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: _ZN9prevectorILj36EhjiE7reserveEj
Unexecuted instantiation: _ZN9prevectorILj8EijiE7reserveEj
306
307
20.5M
    void shrink_to_fit() {
308
20.5M
        change_capacity(size());
309
20.5M
    }
_ZN9prevectorILj36EhjiE13shrink_to_fitEv
Line
Count
Source
307
20.5M
    void shrink_to_fit() {
308
20.5M
        change_capacity(size());
309
20.5M
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE13shrink_to_fitEv
310
311
40.5M
    void clear() {
312
40.5M
        resize(0);
313
40.5M
    }
_ZN9prevectorILj36EhjiE5clearEv
Line
Count
Source
311
40.2M
    void clear() {
312
40.2M
        resize(0);
313
40.2M
    }
_ZN9prevectorILj16EhjiE5clearEv
Line
Count
Source
311
263k
    void clear() {
312
263k
        resize(0);
313
263k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE5clearEv
Unexecuted instantiation: _ZN9prevectorILj33EhjiE5clearEv
314
315
6.23M
    iterator insert(iterator pos, const T& value) {
316
6.23M
        size_type p = pos - begin();
317
6.23M
        size_type new_size = size() + 1;
318
6.23M
        if (capacity() < new_size) {
319
0
            change_capacity(new_size + (new_size >> 1));
320
0
        }
321
6.23M
        T* ptr = item_ptr(p);
322
6.23M
        T* dst = ptr + 1;
323
6.23M
        memmove(dst, ptr, (size() - p) * sizeof(T));
324
6.23M
        _size++;
325
6.23M
        new(static_cast<void*>(ptr)) T(value);
326
6.23M
        return iterator(ptr);
327
6.23M
    }
_ZN9prevectorILj36EhjiE6insertENS0_8iteratorERKh
Line
Count
Source
315
6.23M
    iterator insert(iterator pos, const T& value) {
316
6.23M
        size_type p = pos - begin();
317
6.23M
        size_type new_size = size() + 1;
318
6.23M
        if (capacity() < new_size) {
319
0
            change_capacity(new_size + (new_size >> 1));
320
0
        }
321
6.23M
        T* ptr = item_ptr(p);
322
6.23M
        T* dst = ptr + 1;
323
6.23M
        memmove(dst, ptr, (size() - p) * sizeof(T));
324
6.23M
        _size++;
325
6.23M
        new(static_cast<void*>(ptr)) T(value);
326
6.23M
        return iterator(ptr);
327
6.23M
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE6insertENS0_8iteratorERKi
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: _ZN9prevectorILj8EijiE6insertENS0_8iteratorEjRKi
Unexecuted instantiation: _ZN9prevectorILj36EhjiE6insertENS0_8iteratorEjRKh
341
342
    template <std::input_iterator InputIterator>
343
2.74M
    void insert(iterator pos, InputIterator first, InputIterator last) {
344
2.74M
        size_type p = pos - begin();
345
2.74M
        difference_type count = last - first;
346
2.74M
        size_type new_size = size() + count;
347
2.74M
        if (capacity() < new_size) {
348
427k
            change_capacity(new_size + (new_size >> 1));
349
427k
        }
350
2.74M
        T* ptr = item_ptr(p);
351
2.74M
        T* dst = ptr + count;
352
2.74M
        memmove(dst, ptr, (size() - p) * sizeof(T));
353
2.74M
        _size += count;
354
2.74M
        fill(ptr, first, last);
355
2.74M
    }
Unexecuted instantiation: _ZN9prevectorILj36EhjiE6insertITkNSt3__114input_iteratorEPKhEEvNS0_8iteratorET_S6_
_ZN9prevectorILj36EhjiE6insertITkNSt3__114input_iteratorENS2_11__wrap_iterIPKhEEEEvNS0_8iteratorET_S8_
Line
Count
Source
343
2.74M
    void insert(iterator pos, InputIterator first, InputIterator last) {
344
2.74M
        size_type p = pos - begin();
345
2.74M
        difference_type count = last - first;
346
2.74M
        size_type new_size = size() + count;
347
2.74M
        if (capacity() < new_size) {
348
427k
            change_capacity(new_size + (new_size >> 1));
349
427k
        }
350
2.74M
        T* ptr = item_ptr(p);
351
2.74M
        T* dst = ptr + count;
352
2.74M
        memmove(dst, ptr, (size() - p) * sizeof(T));
353
2.74M
        _size += count;
354
2.74M
        fill(ptr, first, last);
355
2.74M
    }
Unexecuted instantiation: _ZN9prevectorILj36EhjiE6insertITkNSt3__114input_iteratorENS0_8iteratorEEEvS3_T_S4_
Unexecuted instantiation: _ZN9prevectorILj8EijiE6insertITkNSt3__114input_iteratorEPiEEvNS0_8iteratorET_S5_
Unexecuted instantiation: _ZN9prevectorILj36EhjiE6insertITkNSt3__114input_iteratorENS2_11__wrap_iterIPhEEEEvNS0_8iteratorET_S7_
_ZN9prevectorILj35EhjiE6insertITkNSt3__114input_iteratorEPhEEvNS0_8iteratorET_S5_
Line
Count
Source
343
275
    void insert(iterator pos, InputIterator first, InputIterator last) {
344
275
        size_type p = pos - begin();
345
275
        difference_type count = last - first;
346
275
        size_type new_size = size() + count;
347
275
        if (capacity() < new_size) {
348
0
            change_capacity(new_size + (new_size >> 1));
349
0
        }
350
275
        T* ptr = item_ptr(p);
351
275
        T* dst = ptr + count;
352
275
        memmove(dst, ptr, (size() - p) * sizeof(T));
353
275
        _size += count;
354
275
        fill(ptr, first, last);
355
275
    }
_ZN9prevectorILj35EhjiE6insertITkNSt3__114input_iteratorEPKhEEvNS0_8iteratorET_S6_
Line
Count
Source
343
275
    void insert(iterator pos, InputIterator first, InputIterator last) {
344
275
        size_type p = pos - begin();
345
275
        difference_type count = last - first;
346
275
        size_type new_size = size() + count;
347
275
        if (capacity() < new_size) {
348
0
            change_capacity(new_size + (new_size >> 1));
349
0
        }
350
275
        T* ptr = item_ptr(p);
351
275
        T* dst = ptr + count;
352
275
        memmove(dst, ptr, (size() - p) * sizeof(T));
353
275
        _size += count;
354
275
        fill(ptr, first, last);
355
275
    }
Unexecuted instantiation: _ZN9prevectorILj36EhjiE6insertITkNSt3__114input_iteratorENS0_14const_iteratorEEEvNS0_8iteratorET_S5_
356
357
9.42M
    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
9.42M
        if (capacity() < new_size) {
361
2.72M
            change_capacity(new_size);
362
2.72M
            _size += new_size - size();
363
2.72M
            return;
364
2.72M
        }
365
6.69M
        if (new_size < size()) {
366
0
            erase(item_ptr(new_size), end());
367
6.69M
        } else {
368
6.69M
            _size += new_size - size();
369
6.69M
        }
370
6.69M
    }
_ZN9prevectorILj36EhjiE20resize_uninitializedEj
Line
Count
Source
357
9.42M
    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
9.42M
        if (capacity() < new_size) {
361
2.72M
            change_capacity(new_size);
362
2.72M
            _size += new_size - size();
363
2.72M
            return;
364
2.72M
        }
365
6.69M
        if (new_size < size()) {
366
0
            erase(item_ptr(new_size), end());
367
6.69M
        } else {
368
6.69M
            _size += new_size - size();
369
6.69M
        }
370
6.69M
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE20resize_uninitializedEj
371
372
0
    iterator erase(iterator pos) {
373
0
        return erase(pos, pos + 1);
374
0
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE5eraseENS0_8iteratorE
Unexecuted instantiation: _ZN9prevectorILj33EhjiE5eraseENS0_8iteratorE
375
376
993k
    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
993k
        iterator p = first;
384
993k
        char* endp = (char*)&(*end());
385
993k
        _size -= last - p;
386
993k
        memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
387
993k
        return first;
388
993k
    }
_ZN9prevectorILj36EhjiE5eraseENS0_8iteratorES1_
Line
Count
Source
376
614k
    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
614k
        iterator p = first;
384
614k
        char* endp = (char*)&(*end());
385
614k
        _size -= last - p;
386
614k
        memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
387
614k
        return first;
388
614k
    }
_ZN9prevectorILj16EhjiE5eraseENS0_8iteratorES1_
Line
Count
Source
376
378k
    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
378k
        iterator p = first;
384
378k
        char* endp = (char*)&(*end());
385
378k
        _size -= last - p;
386
378k
        memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
387
378k
        return first;
388
378k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiE5eraseENS0_8iteratorES1_
Unexecuted instantiation: _ZN9prevectorILj33EhjiE5eraseENS0_8iteratorES1_
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: _ZN9prevectorILj36EhjiE12emplace_backIJRKhEEEvDpOT_
Unexecuted instantiation: _ZN9prevectorILj8EijiE12emplace_backIJRKiEEEvDpOT_
399
400
0
    void push_back(const T& value) {
401
0
        emplace_back(value);
402
0
    }
Unexecuted instantiation: _ZN9prevectorILj36EhjiE9push_backERKh
Unexecuted instantiation: _ZN9prevectorILj8EijiE9push_backERKi
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
0
    const T& back() const {
421
0
        return *item_ptr(size() - 1);
422
0
    }
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
82.0M
    ~prevector() {
431
82.0M
        if (!is_direct()) {
432
9.10M
            free(_union.indirect_contents.indirect);
433
9.10M
            _union.indirect_contents.indirect = nullptr;
434
9.10M
        }
435
82.0M
    }
_ZN9prevectorILj16EhjiED2Ev
Line
Count
Source
430
2.50M
    ~prevector() {
431
2.50M
        if (!is_direct()) {
432
312k
            free(_union.indirect_contents.indirect);
433
312k
            _union.indirect_contents.indirect = nullptr;
434
312k
        }
435
2.50M
    }
_ZN9prevectorILj36EhjiED2Ev
Line
Count
Source
430
79.4M
    ~prevector() {
431
79.4M
        if (!is_direct()) {
432
8.79M
            free(_union.indirect_contents.indirect);
433
8.79M
            _union.indirect_contents.indirect = nullptr;
434
8.79M
        }
435
79.4M
    }
_ZN9prevectorILj33EhjiED2Ev
Line
Count
Source
430
52.9k
    ~prevector() {
431
52.9k
        if (!is_direct()) {
432
0
            free(_union.indirect_contents.indirect);
433
0
            _union.indirect_contents.indirect = nullptr;
434
0
        }
435
52.9k
    }
Unexecuted instantiation: _ZN9prevectorILj8EijiED2Ev
_ZN9prevectorILj35EhjiED2Ev
Line
Count
Source
430
275
    ~prevector() {
431
275
        if (!is_direct()) {
432
0
            free(_union.indirect_contents.indirect);
433
0
            _union.indirect_contents.indirect = nullptr;
434
0
        }
435
275
    }
436
437
619k
    bool operator==(const prevector<N, T, Size, Diff>& other) const {
438
619k
        if (other.size() != size()) {
439
0
            return false;
440
0
        }
441
619k
        const_iterator b1 = begin();
442
619k
        const_iterator b2 = other.begin();
443
619k
        const_iterator e1 = end();
444
19.0M
        while (b1 != e1) {
445
18.5M
            if ((*b1) != (*b2)) {
446
73.8k
                return false;
447
73.8k
            }
448
18.4M
            ++b1;
449
18.4M
            ++b2;
450
18.4M
        }
451
545k
        return true;
452
619k
    }
_ZNK9prevectorILj36EhjiEeqERKS0_
Line
Count
Source
437
545k
    bool operator==(const prevector<N, T, Size, Diff>& other) const {
438
545k
        if (other.size() != size()) {
439
0
            return false;
440
0
        }
441
545k
        const_iterator b1 = begin();
442
545k
        const_iterator b2 = other.begin();
443
545k
        const_iterator e1 = end();
444
18.9M
        while (b1 != e1) {
445
18.3M
            if ((*b1) != (*b2)) {
446
0
                return false;
447
0
            }
448
18.3M
            ++b1;
449
18.3M
            ++b2;
450
18.3M
        }
451
545k
        return true;
452
545k
    }
Unexecuted instantiation: _ZNK9prevectorILj8EijiEeqERKS0_
_ZNK9prevectorILj16EhjiEeqERKS0_
Line
Count
Source
437
74.4k
    bool operator==(const prevector<N, T, Size, Diff>& other) const {
438
74.4k
        if (other.size() != size()) {
439
0
            return false;
440
0
        }
441
74.4k
        const_iterator b1 = begin();
442
74.4k
        const_iterator b2 = other.begin();
443
74.4k
        const_iterator e1 = end();
444
139k
        while (b1 != e1) {
445
139k
            if ((*b1) != (*b2)) {
446
73.8k
                return false;
447
73.8k
            }
448
65.5k
            ++b1;
449
65.5k
            ++b2;
450
65.5k
        }
451
536
        return true;
452
74.4k
    }
453
454
0
    bool operator!=(const prevector<N, T, Size, Diff>& other) const {
455
0
        return !(*this == other);
456
0
    }
457
458
0
    bool operator<(const prevector<N, T, Size, Diff>& other) const {
459
0
        if (size() < other.size()) {
460
0
            return true;
461
0
        }
462
0
        if (size() > other.size()) {
463
0
            return false;
464
0
        }
465
0
        const_iterator b1 = begin();
466
0
        const_iterator b2 = other.begin();
467
0
        const_iterator e1 = end();
468
0
        while (b1 != e1) {
469
0
            if ((*b1) < (*b2)) {
470
0
                return true;
471
0
            }
472
0
            if ((*b2) < (*b1)) {
473
0
                return false;
474
0
            }
475
0
            ++b1;
476
0
            ++b2;
477
0
        }
478
0
        return false;
479
0
    }
Unexecuted instantiation: _ZNK9prevectorILj36EhjiEltERKS0_
Unexecuted instantiation: _ZNK9prevectorILj16EhjiEltERKS0_
480
481
9.11M
    size_t allocated_memory() const {
482
9.11M
        if (is_direct()) {
483
9.10M
            return 0;
484
9.10M
        } else {
485
4.80k
            return ((size_t)(sizeof(T))) * _union.indirect_contents.capacity;
486
4.80k
        }
487
9.11M
    }
488
489
1.37M
    value_type* data() {
490
1.37M
        return item_ptr(0);
491
1.37M
    }
Unexecuted instantiation: _ZN9prevectorILj33EhjiE4dataEv
_ZN9prevectorILj36EhjiE4dataEv
Line
Count
Source
489
1.14M
    value_type* data() {
490
1.14M
        return item_ptr(0);
491
1.14M
    }
_ZN9prevectorILj16EhjiE4dataEv
Line
Count
Source
489
229k
    value_type* data() {
490
229k
        return item_ptr(0);
491
229k
    }
_ZN9prevectorILj35EhjiE4dataEv
Line
Count
Source
489
275
    value_type* data() {
490
275
        return item_ptr(0);
491
275
    }
492
493
64.4M
    const value_type* data() const {
494
64.4M
        return item_ptr(0);
495
64.4M
    }
_ZNK9prevectorILj36EhjiE4dataEv
Line
Count
Source
493
63.0M
    const value_type* data() const {
494
63.0M
        return item_ptr(0);
495
63.0M
    }
_ZNK9prevectorILj16EhjiE4dataEv
Line
Count
Source
493
1.36M
    const value_type* data() const {
494
1.36M
        return item_ptr(0);
495
1.36M
    }
Unexecuted instantiation: _ZNK9prevectorILj33EhjiE4dataEv
496
};
497
498
#endif // BITCOIN_PREVECTOR_H