/tmp/bitcoin/src/util/vector.h
Line | Count | Source |
1 | | // Copyright (c) 2019-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_UTIL_VECTOR_H |
6 | | #define BITCOIN_UTIL_VECTOR_H |
7 | | |
8 | | #include <functional> |
9 | | #include <initializer_list> |
10 | | #include <optional> |
11 | | #include <type_traits> |
12 | | #include <utility> |
13 | | #include <vector> |
14 | | |
15 | | /** Construct a vector with the specified elements. |
16 | | * |
17 | | * This is preferable over the list initializing constructor of std::vector: |
18 | | * - It automatically infers the element type from its arguments. |
19 | | * - If any arguments are rvalue references, they will be moved into the vector |
20 | | * (list initialization always copies). |
21 | | */ |
22 | | template<typename... Args> |
23 | | inline std::vector<std::common_type_t<Args...>> Vector(Args&&... args) |
24 | 8.77M | { |
25 | 8.77M | std::vector<std::common_type_t<Args...>> ret; |
26 | 8.77M | ret.reserve(sizeof...(args)); |
27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html |
28 | 8.77M | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; |
29 | 8.77M | return ret; |
30 | 8.77M | } std::vector<std::common_type<std::vector<unsigned char, std::allocator<unsigned char>>>::type, std::allocator<std::common_type<std::vector<unsigned char, std::allocator<unsigned char>>>::type>> Vector<std::vector<unsigned char, std::allocator<unsigned char>>>(std::vector<unsigned char, std::allocator<unsigned char>>&&) Line | Count | Source | 24 | 489k | { | 25 | 489k | std::vector<std::common_type_t<Args...>> ret; | 26 | 489k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 489k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 489k | return ret; | 30 | 489k | } |
std::vector<std::common_type<miniscript::internal::InputStack const&>::type, std::allocator<std::common_type<miniscript::internal::InputStack const&>::type>> Vector<miniscript::internal::InputStack const&>(miniscript::internal::InputStack const&) Line | Count | Source | 24 | 1.82k | { | 25 | 1.82k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.82k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1.82k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.82k | return ret; | 30 | 1.82k | } |
std::vector<std::common_type<unsigned char>::type, std::allocator<std::common_type<unsigned char>::type>> Vector<unsigned char>(unsigned char&&) Line | Count | Source | 24 | 4.51k | { | 25 | 4.51k | std::vector<std::common_type_t<Args...>> ret; | 26 | 4.51k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 4.51k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 4.51k | return ret; | 30 | 4.51k | } |
std::vector<std::common_type<miniscript::Node<CPubKey>>::type, std::allocator<std::common_type<miniscript::Node<CPubKey>>::type>> Vector<miniscript::Node<CPubKey>>(miniscript::Node<CPubKey>&&) Line | Count | Source | 24 | 10.0k | { | 25 | 10.0k | std::vector<std::common_type_t<Args...>> ret; | 26 | 10.0k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 10.0k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 10.0k | return ret; | 30 | 10.0k | } |
std::vector<std::common_type<CPubKey>::type, std::allocator<std::common_type<CPubKey>::type>> Vector<CPubKey>(CPubKey&&) Line | Count | Source | 24 | 1.89k | { | 25 | 1.89k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.89k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1.89k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.89k | return ret; | 30 | 1.89k | } |
std::vector<std::common_type<miniscript::internal::MaxInt<unsigned int>>::type, std::allocator<std::common_type<miniscript::internal::MaxInt<unsigned int>>::type>> Vector<miniscript::internal::MaxInt<unsigned int>>(miniscript::internal::MaxInt<unsigned int>&&) Line | Count | Source | 24 | 3.82k | { | 25 | 3.82k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.82k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 3.82k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.82k | return ret; | 30 | 3.82k | } |
std::vector<std::common_type<miniscript::internal::SatInfo>::type, std::allocator<std::common_type<miniscript::internal::SatInfo>::type>> Vector<miniscript::internal::SatInfo>(miniscript::internal::SatInfo&&) Line | Count | Source | 24 | 1.91k | { | 25 | 1.91k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.91k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1.91k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.91k | return ret; | 30 | 1.91k | } |
std::vector<std::common_type<miniscript::Node<CPubKey>, miniscript::Node<CPubKey>>::type, std::allocator<std::common_type<miniscript::Node<CPubKey>, miniscript::Node<CPubKey>>::type>> Vector<miniscript::Node<CPubKey>, miniscript::Node<CPubKey>>(miniscript::Node<CPubKey>&&, miniscript::Node<CPubKey>&&) Line | Count | Source | 24 | 7.68k | { | 25 | 7.68k | std::vector<std::common_type_t<Args...>> ret; | 26 | 7.68k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 7.68k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 7.68k | return ret; | 30 | 7.68k | } |
std::vector<std::common_type<miniscript::Node<CPubKey>, miniscript::Node<CPubKey>, miniscript::Node<CPubKey>>::type, std::allocator<std::common_type<miniscript::Node<CPubKey>, miniscript::Node<CPubKey>, miniscript::Node<CPubKey>>::type>> Vector<miniscript::Node<CPubKey>, miniscript::Node<CPubKey>, miniscript::Node<CPubKey>>(miniscript::Node<CPubKey>&&, miniscript::Node<CPubKey>&&, miniscript::Node<CPubKey>&&) Line | Count | Source | 24 | 140 | { | 25 | 140 | std::vector<std::common_type_t<Args...>> ret; | 26 | 140 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 140 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 140 | return ret; | 30 | 140 | } |
std::vector<std::common_type<miniscript::Node<unsigned int>>::type, std::allocator<std::common_type<miniscript::Node<unsigned int>>::type>> Vector<miniscript::Node<unsigned int>>(miniscript::Node<unsigned int>&&) Line | Count | Source | 24 | 1.19M | { | 25 | 1.19M | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.19M | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1.19M | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.19M | return ret; | 30 | 1.19M | } |
util_tests.cpp:std::vector<std::common_type<util_tests::(anonymous namespace)::Tracker&>::type, std::allocator<std::common_type<util_tests::(anonymous namespace)::Tracker&>::type>> Vector<util_tests::(anonymous namespace)::Tracker&>(util_tests::(anonymous namespace)::Tracker&) Line | Count | Source | 24 | 1 | { | 25 | 1 | std::vector<std::common_type_t<Args...>> ret; | 26 | 1 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1 | return ret; | 30 | 1 | } |
util_tests.cpp:std::vector<std::common_type<util_tests::(anonymous namespace)::Tracker>::type, std::allocator<std::common_type<util_tests::(anonymous namespace)::Tracker>::type>> Vector<util_tests::(anonymous namespace)::Tracker>(util_tests::(anonymous namespace)::Tracker&&) Line | Count | Source | 24 | 1 | { | 25 | 1 | std::vector<std::common_type_t<Args...>> ret; | 26 | 1 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1 | return ret; | 30 | 1 | } |
util_tests.cpp:std::vector<std::common_type<util_tests::(anonymous namespace)::Tracker&, util_tests::(anonymous namespace)::Tracker>::type, std::allocator<std::common_type<util_tests::(anonymous namespace)::Tracker&, util_tests::(anonymous namespace)::Tracker>::type>> Vector<util_tests::(anonymous namespace)::Tracker&, util_tests::(anonymous namespace)::Tracker>(util_tests::(anonymous namespace)::Tracker&, util_tests::(anonymous namespace)::Tracker&&) Line | Count | Source | 24 | 1 | { | 25 | 1 | std::vector<std::common_type_t<Args...>> ret; | 26 | 1 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1 | return ret; | 30 | 1 | } |
util_tests.cpp:std::vector<std::common_type<util_tests::(anonymous namespace)::Tracker, util_tests::(anonymous namespace)::Tracker&, util_tests::(anonymous namespace)::Tracker>::type, std::allocator<std::common_type<util_tests::(anonymous namespace)::Tracker, util_tests::(anonymous namespace)::Tracker&, util_tests::(anonymous namespace)::Tracker>::type>> Vector<util_tests::(anonymous namespace)::Tracker, util_tests::(anonymous namespace)::Tracker&, util_tests::(anonymous namespace)::Tracker>(util_tests::(anonymous namespace)::Tracker&&, util_tests::(anonymous namespace)::Tracker&, util_tests::(anonymous namespace)::Tracker&&) Line | Count | Source | 24 | 1 | { | 25 | 1 | std::vector<std::common_type_t<Args...>> ret; | 26 | 1 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1 | return ret; | 30 | 1 | } |
std::vector<std::common_type<uint256 const&, uint256&>::type, std::allocator<std::common_type<uint256 const&, uint256&>::type>> Vector<uint256 const&, uint256&>(uint256 const&, uint256&) Line | Count | Source | 24 | 3.71k | { | 25 | 3.71k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.71k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 3.71k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.71k | return ret; | 30 | 3.71k | } |
descriptor.cpp:std::vector<std::common_type<std::unique_ptr<(anonymous namespace)::PubkeyProvider, std::default_delete<(anonymous namespace)::PubkeyProvider>>>::type, std::allocator<std::common_type<std::unique_ptr<(anonymous namespace)::PubkeyProvider, std::default_delete<(anonymous namespace)::PubkeyProvider>>>::type>> Vector<std::unique_ptr<(anonymous namespace)::PubkeyProvider, std::default_delete<(anonymous namespace)::PubkeyProvider>>>(std::unique_ptr<(anonymous namespace)::PubkeyProvider, std::default_delete<(anonymous namespace)::PubkeyProvider>>&&) Line | Count | Source | 24 | 353k | { | 25 | 353k | std::vector<std::common_type_t<Args...>> ret; | 26 | 353k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 353k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 353k | return ret; | 30 | 353k | } |
std::vector<std::common_type<CScript>::type, std::allocator<std::common_type<CScript>::type>> Vector<CScript>(CScript&&) Line | Count | Source | 24 | 720k | { | 25 | 720k | std::vector<std::common_type_t<Args...>> ret; | 26 | 720k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 720k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 720k | return ret; | 30 | 720k | } |
descriptor.cpp:std::vector<std::common_type<std::unique_ptr<(anonymous namespace)::DescriptorImpl, std::default_delete<(anonymous namespace)::DescriptorImpl>>>::type, std::allocator<std::common_type<std::unique_ptr<(anonymous namespace)::DescriptorImpl, std::default_delete<(anonymous namespace)::DescriptorImpl>>>::type>> Vector<std::unique_ptr<(anonymous namespace)::DescriptorImpl, std::default_delete<(anonymous namespace)::DescriptorImpl>>>(std::unique_ptr<(anonymous namespace)::DescriptorImpl, std::default_delete<(anonymous namespace)::DescriptorImpl>>&&) Line | Count | Source | 24 | 36.8k | { | 25 | 36.8k | std::vector<std::common_type_t<Args...>> ret; | 26 | 36.8k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 36.8k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 36.8k | return ret; | 30 | 36.8k | } |
std::vector<std::common_type<CScript const&>::type, std::allocator<std::common_type<CScript const&>::type>> Vector<CScript const&>(CScript const&) Line | Count | Source | 24 | 1.91k | { | 25 | 1.91k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.91k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1.91k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.91k | return ret; | 30 | 1.91k | } |
std::vector<std::common_type<unsigned int>::type, std::allocator<std::common_type<unsigned int>::type>> Vector<unsigned int>(unsigned int&&) Line | Count | Source | 24 | 1.56k | { | 25 | 1.56k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.56k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1.56k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.56k | return ret; | 30 | 1.56k | } |
std::vector<std::common_type<miniscript::Node<unsigned int>, miniscript::Node<unsigned int>>::type, std::allocator<std::common_type<miniscript::Node<unsigned int>, miniscript::Node<unsigned int>>::type>> Vector<miniscript::Node<unsigned int>, miniscript::Node<unsigned int>>(miniscript::Node<unsigned int>&&, miniscript::Node<unsigned int>&&) Line | Count | Source | 24 | 1.14k | { | 25 | 1.14k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.14k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 1.14k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.14k | return ret; | 30 | 1.14k | } |
std::vector<std::common_type<miniscript::Node<unsigned int>, miniscript::Node<unsigned int>, miniscript::Node<unsigned int>>::type, std::allocator<std::common_type<miniscript::Node<unsigned int>, miniscript::Node<unsigned int>, miniscript::Node<unsigned int>>::type>> Vector<miniscript::Node<unsigned int>, miniscript::Node<unsigned int>, miniscript::Node<unsigned int>>(miniscript::Node<unsigned int>&&, miniscript::Node<unsigned int>&&, miniscript::Node<unsigned int>&&) Line | Count | Source | 24 | 114 | { | 25 | 114 | std::vector<std::common_type_t<Args...>> ret; | 26 | 114 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 114 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 114 | return ret; | 30 | 114 | } |
std::vector<std::common_type<std::vector<unsigned char, std::allocator<unsigned char>>&>::type, std::allocator<std::common_type<std::vector<unsigned char, std::allocator<unsigned char>>&>::type>> Vector<std::vector<unsigned char, std::allocator<unsigned char>>&>(std::vector<unsigned char, std::allocator<unsigned char>>&) Line | Count | Source | 24 | 827 | { | 25 | 827 | std::vector<std::common_type_t<Args...>> ret; | 26 | 827 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 827 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 827 | return ret; | 30 | 827 | } |
std::vector<std::common_type<XOnlyPubKey>::type, std::allocator<std::common_type<XOnlyPubKey>::type>> Vector<XOnlyPubKey>(XOnlyPubKey&&) Line | Count | Source | 24 | 3.41k | { | 25 | 3.41k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.41k | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 3.41k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.41k | return ret; | 30 | 3.41k | } |
std::vector<std::common_type<miniscript::Node<XOnlyPubKey>>::type, std::allocator<std::common_type<miniscript::Node<XOnlyPubKey>>::type>> Vector<miniscript::Node<XOnlyPubKey>>(miniscript::Node<XOnlyPubKey>&&) Line | Count | Source | 24 | 5.93M | { | 25 | 5.93M | std::vector<std::common_type_t<Args...>> ret; | 26 | 5.93M | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 5.93M | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 5.93M | return ret; | 30 | 5.93M | } |
std::vector<std::common_type<miniscript::Node<XOnlyPubKey>, miniscript::Node<XOnlyPubKey>>::type, std::allocator<std::common_type<miniscript::Node<XOnlyPubKey>, miniscript::Node<XOnlyPubKey>>::type>> Vector<miniscript::Node<XOnlyPubKey>, miniscript::Node<XOnlyPubKey>>(miniscript::Node<XOnlyPubKey>&&, miniscript::Node<XOnlyPubKey>&&) Line | Count | Source | 24 | 852 | { | 25 | 852 | std::vector<std::common_type_t<Args...>> ret; | 26 | 852 | ret.reserve(sizeof...(args)); | 27 | | // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html | 28 | 852 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 852 | return ret; | 30 | 852 | } |
Unexecuted instantiation: std::vector<std::common_type<miniscript::Node<XOnlyPubKey>, miniscript::Node<XOnlyPubKey>, miniscript::Node<XOnlyPubKey>>::type, std::allocator<std::common_type<miniscript::Node<XOnlyPubKey>, miniscript::Node<XOnlyPubKey>, miniscript::Node<XOnlyPubKey>>::type>> Vector<miniscript::Node<XOnlyPubKey>, miniscript::Node<XOnlyPubKey>, miniscript::Node<XOnlyPubKey>>(miniscript::Node<XOnlyPubKey>&&, miniscript::Node<XOnlyPubKey>&&, miniscript::Node<XOnlyPubKey>&&) |
31 | | |
32 | | /** Concatenate two vectors, moving elements. */ |
33 | | template<typename V> |
34 | | inline V Cat(V v1, V&& v2) |
35 | 89.6M | { |
36 | 89.6M | v1.reserve(v1.size() + v2.size()); |
37 | 89.6M | for (auto& arg : v2) { |
38 | 45.3M | v1.push_back(std::move(arg)); |
39 | 45.3M | } |
40 | 89.6M | return v1; |
41 | 89.6M | } util_tests.cpp:std::vector<util_tests::(anonymous namespace)::Tracker, std::allocator<util_tests::(anonymous namespace)::Tracker>> Cat<std::vector<util_tests::(anonymous namespace)::Tracker, std::allocator<util_tests::(anonymous namespace)::Tracker>>>(std::vector<util_tests::(anonymous namespace)::Tracker, std::allocator<util_tests::(anonymous namespace)::Tracker>>, std::vector<util_tests::(anonymous namespace)::Tracker, std::allocator<util_tests::(anonymous namespace)::Tracker>>&&) Line | Count | Source | 35 | 2 | { | 36 | 2 | v1.reserve(v1.size() + v2.size()); | 37 | 5 | for (auto& arg : v2) { | 38 | 5 | v1.push_back(std::move(arg)); | 39 | 5 | } | 40 | 2 | return v1; | 41 | 2 | } |
std::vector<char const*, std::allocator<char const*>> Cat<std::vector<char const*, std::allocator<char const*>>>(std::vector<char const*, std::allocator<char const*>>, std::vector<char const*, std::allocator<char const*>>&&) Line | Count | Source | 35 | 682 | { | 36 | 682 | v1.reserve(v1.size() + v2.size()); | 37 | 682 | for (auto& arg : v2) { | 38 | 682 | v1.push_back(std::move(arg)); | 39 | 682 | } | 40 | 682 | return v1; | 41 | 682 | } |
std::vector<RPCResult, std::allocator<RPCResult>> Cat<std::vector<RPCResult, std::allocator<RPCResult>>>(std::vector<RPCResult, std::allocator<RPCResult>>, std::vector<RPCResult, std::allocator<RPCResult>>&&) Line | Count | Source | 35 | 34.9k | { | 36 | 34.9k | v1.reserve(v1.size() + v2.size()); | 37 | 132k | for (auto& arg : v2) { | 38 | 132k | v1.push_back(std::move(arg)); | 39 | 132k | } | 40 | 34.9k | return v1; | 41 | 34.9k | } |
std::vector<RPCArg, std::allocator<RPCArg>> Cat<std::vector<RPCArg, std::allocator<RPCArg>>>(std::vector<RPCArg, std::allocator<RPCArg>>, std::vector<RPCArg, std::allocator<RPCArg>>&&) Line | Count | Source | 35 | 8.33k | { | 36 | 8.33k | v1.reserve(v1.size() + v2.size()); | 37 | 19.7k | for (auto& arg : v2) { | 38 | 19.7k | v1.push_back(std::move(arg)); | 39 | 19.7k | } | 40 | 8.33k | return v1; | 41 | 8.33k | } |
std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> Cat<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&&) Line | Count | Source | 35 | 46 | { | 36 | 46 | v1.reserve(v1.size() + v2.size()); | 37 | 124 | for (auto& arg : v2) { | 38 | 124 | v1.push_back(std::move(arg)); | 39 | 124 | } | 40 | 46 | return v1; | 41 | 46 | } |
std::vector<std::vector<unsigned char, std::allocator<unsigned char>>, std::allocator<std::vector<unsigned char, std::allocator<unsigned char>>>> Cat<std::vector<std::vector<unsigned char, std::allocator<unsigned char>>, std::allocator<std::vector<unsigned char, std::allocator<unsigned char>>>>>(std::vector<std::vector<unsigned char, std::allocator<unsigned char>>, std::allocator<std::vector<unsigned char, std::allocator<unsigned char>>>>, std::vector<std::vector<unsigned char, std::allocator<unsigned char>>, std::allocator<std::vector<unsigned char, std::allocator<unsigned char>>>>&&) Line | Count | Source | 35 | 89.6M | { | 36 | 89.6M | v1.reserve(v1.size() + v2.size()); | 37 | 89.6M | for (auto& arg : v2) { | 38 | 45.1M | v1.push_back(std::move(arg)); | 39 | 45.1M | } | 40 | 89.6M | return v1; | 41 | 89.6M | } |
|
42 | | |
43 | | /** Concatenate two vectors. */ |
44 | | template<typename V> |
45 | | inline V Cat(V v1, const V& v2) |
46 | 699 | { |
47 | 699 | v1.reserve(v1.size() + v2.size()); |
48 | 699 | for (const auto& arg : v2) { |
49 | 31 | v1.push_back(arg); |
50 | 31 | } |
51 | 699 | return v1; |
52 | 699 | } util_tests.cpp:std::vector<util_tests::(anonymous namespace)::Tracker, std::allocator<util_tests::(anonymous namespace)::Tracker>> Cat<std::vector<util_tests::(anonymous namespace)::Tracker, std::allocator<util_tests::(anonymous namespace)::Tracker>>>(std::vector<util_tests::(anonymous namespace)::Tracker, std::allocator<util_tests::(anonymous namespace)::Tracker>>, std::vector<util_tests::(anonymous namespace)::Tracker, std::allocator<util_tests::(anonymous namespace)::Tracker>> const&) Line | Count | Source | 46 | 2 | { | 47 | 2 | v1.reserve(v1.size() + v2.size()); | 48 | 5 | for (const auto& arg : v2) { | 49 | 5 | v1.push_back(arg); | 50 | 5 | } | 51 | 2 | return v1; | 52 | 2 | } |
std::vector<char const*, std::allocator<char const*>> Cat<std::vector<char const*, std::allocator<char const*>>>(std::vector<char const*, std::allocator<char const*>>, std::vector<char const*, std::allocator<char const*>> const&) Line | Count | Source | 46 | 697 | { | 47 | 697 | v1.reserve(v1.size() + v2.size()); | 48 | 697 | for (const auto& arg : v2) { | 49 | 26 | v1.push_back(arg); | 50 | 26 | } | 51 | 697 | return v1; | 52 | 697 | } |
|
53 | | |
54 | | /** Clear a vector (or std::deque) and release its allocated memory. */ |
55 | | template<typename V> |
56 | | inline void ClearShrink(V& v) noexcept |
57 | 1.06M | { |
58 | | // There are various ways to clear a vector and release its memory: |
59 | | // |
60 | | // 1. V{}.swap(v) |
61 | | // 2. v = V{} |
62 | | // 3. v = {}; v.shrink_to_fit(); |
63 | | // 4. v.clear(); v.shrink_to_fit(); |
64 | | // |
65 | | // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit() |
66 | | // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding |
67 | | // request. Therefore, we use method (1). |
68 | | |
69 | 1.06M | V{}.swap(v); |
70 | 1.06M | } void ClearShrink<std::vector<unsigned char, std::allocator<unsigned char>>>(std::vector<unsigned char, std::allocator<unsigned char>>&) Line | Count | Source | 57 | 359k | { | 58 | | // There are various ways to clear a vector and release its memory: | 59 | | // | 60 | | // 1. V{}.swap(v) | 61 | | // 2. v = V{} | 62 | | // 3. v = {}; v.shrink_to_fit(); | 63 | | // 4. v.clear(); v.shrink_to_fit(); | 64 | | // | 65 | | // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit() | 66 | | // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding | 67 | | // request. Therefore, we use method (1). | 68 | | | 69 | 359k | V{}.swap(v); | 70 | 359k | } |
void ClearShrink<std::vector<bool, std::allocator<bool>>>(std::vector<bool, std::allocator<bool>>&) Line | Count | Source | 57 | 1 | { | 58 | | // There are various ways to clear a vector and release its memory: | 59 | | // | 60 | | // 1. V{}.swap(v) | 61 | | // 2. v = V{} | 62 | | // 3. v = {}; v.shrink_to_fit(); | 63 | | // 4. v.clear(); v.shrink_to_fit(); | 64 | | // | 65 | | // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit() | 66 | | // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding | 67 | | // request. Therefore, we use method (1). | 68 | | | 69 | 1 | V{}.swap(v); | 70 | 1 | } |
void ClearShrink<std::deque<int, std::allocator<int>>>(std::deque<int, std::allocator<int>>&) Line | Count | Source | 57 | 1 | { | 58 | | // There are various ways to clear a vector and release its memory: | 59 | | // | 60 | | // 1. V{}.swap(v) | 61 | | // 2. v = V{} | 62 | | // 3. v = {}; v.shrink_to_fit(); | 63 | | // 4. v.clear(); v.shrink_to_fit(); | 64 | | // | 65 | | // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit() | 66 | | // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding | 67 | | // request. Therefore, we use method (1). | 68 | | | 69 | 1 | V{}.swap(v); | 70 | 1 | } |
void ClearShrink<bitdeque<32768>>(bitdeque<32768>&) Line | Count | Source | 57 | 12 | { | 58 | | // There are various ways to clear a vector and release its memory: | 59 | | // | 60 | | // 1. V{}.swap(v) | 61 | | // 2. v = V{} | 62 | | // 3. v = {}; v.shrink_to_fit(); | 63 | | // 4. v.clear(); v.shrink_to_fit(); | 64 | | // | 65 | | // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit() | 66 | | // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding | 67 | | // request. Therefore, we use method (1). | 68 | | | 69 | 12 | V{}.swap(v); | 70 | 12 | } |
void ClearShrink<std::deque<CompressedHeader, std::allocator<CompressedHeader>>>(std::deque<CompressedHeader, std::allocator<CompressedHeader>>&) Line | Count | Source | 57 | 12 | { | 58 | | // There are various ways to clear a vector and release its memory: | 59 | | // | 60 | | // 1. V{}.swap(v) | 61 | | // 2. v = V{} | 62 | | // 3. v = {}; v.shrink_to_fit(); | 63 | | // 4. v.clear(); v.shrink_to_fit(); | 64 | | // | 65 | | // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit() | 66 | | // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding | 67 | | // request. Therefore, we use method (1). | 68 | | | 69 | 12 | V{}.swap(v); | 70 | 12 | } |
txgraph.cpp:void ClearShrink<std::vector<std::_Node_handle<(anonymous namespace)::TxGraphImpl::ChunkData, (anonymous namespace)::TxGraphImpl::ChunkData, std::allocator<std::_Rb_tree_node<(anonymous namespace)::TxGraphImpl::ChunkData>>>, std::allocator<std::_Node_handle<(anonymous namespace)::TxGraphImpl::ChunkData, (anonymous namespace)::TxGraphImpl::ChunkData, std::allocator<std::_Rb_tree_node<(anonymous namespace)::TxGraphImpl::ChunkData>>>>>>(std::vector<std::_Node_handle<(anonymous namespace)::TxGraphImpl::ChunkData, (anonymous namespace)::TxGraphImpl::ChunkData, std::allocator<std::_Rb_tree_node<(anonymous namespace)::TxGraphImpl::ChunkData>>>, std::allocator<std::_Node_handle<(anonymous namespace)::TxGraphImpl::ChunkData, (anonymous namespace)::TxGraphImpl::ChunkData, std::allocator<std::_Rb_tree_node<(anonymous namespace)::TxGraphImpl::ChunkData>>>>>&) Line | Count | Source | 57 | 702k | { | 58 | | // There are various ways to clear a vector and release its memory: | 59 | | // | 60 | | // 1. V{}.swap(v) | 61 | | // 2. v = V{} | 62 | | // 3. v = {}; v.shrink_to_fit(); | 63 | | // 4. v.clear(); v.shrink_to_fit(); | 64 | | // | 65 | | // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit() | 66 | | // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding | 67 | | // request. Therefore, we use method (1). | 68 | | | 69 | 702k | V{}.swap(v); | 70 | 702k | } |
|
71 | | |
72 | | template<typename V, typename L> |
73 | | inline std::optional<V> FindFirst(const std::vector<V>& vec, const L fnc) |
74 | 129 | { |
75 | 293 | for (const auto& el : vec) { |
76 | 293 | if (fnc(el)) { |
77 | 108 | return el; |
78 | 108 | } |
79 | 293 | } |
80 | 21 | return std::nullopt; |
81 | 129 | } std::optional<auto> FindFirst<AssumeutxoData, CChainParams::AssumeutxoForHeight(int) const::'lambda'(auto const&)>(std::vector<auto, std::allocator<auto>> const&, CChainParams::AssumeutxoForHeight(int) const::'lambda'(auto const&)) Line | Count | Source | 74 | 62 | { | 75 | 134 | for (const auto& el : vec) { | 76 | 134 | if (fnc(el)) { | 77 | 56 | return el; | 78 | 56 | } | 79 | 134 | } | 80 | 6 | return std::nullopt; | 81 | 62 | } |
std::optional<auto> FindFirst<AssumeutxoData, CChainParams::AssumeutxoForBlockhash(uint256 const&) const::'lambda'(auto const&)>(std::vector<auto, std::allocator<auto>> const&, CChainParams::AssumeutxoForBlockhash(uint256 const&) const::'lambda'(auto const&)) Line | Count | Source | 74 | 67 | { | 75 | 159 | for (const auto& el : vec) { | 76 | 159 | if (fnc(el)) { | 77 | 52 | return el; | 78 | 52 | } | 79 | 159 | } | 80 | 15 | return std::nullopt; | 81 | 67 | } |
|
82 | | |
83 | | #endif // BITCOIN_UTIL_VECTOR_H |