/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 | 9.08M | { |
25 | 9.08M | std::vector<std::common_type_t<Args...>> ret; |
26 | 9.08M | 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 | 9.08M | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; |
29 | 9.08M | return ret; |
30 | 9.08M | } 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 | 486k | { | 25 | 486k | std::vector<std::common_type_t<Args...>> ret; | 26 | 486k | 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 | 486k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 486k | return ret; | 30 | 486k | } |
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.78k | { | 25 | 1.78k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.78k | 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.78k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.78k | return ret; | 30 | 1.78k | } |
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.44k | { | 25 | 4.44k | std::vector<std::common_type_t<Args...>> ret; | 26 | 4.44k | 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.44k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 4.44k | return ret; | 30 | 4.44k | } |
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 | 9.96k | { | 25 | 9.96k | std::vector<std::common_type_t<Args...>> ret; | 26 | 9.96k | 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 | 9.96k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 9.96k | return ret; | 30 | 9.96k | } |
std::vector<std::common_type<CPubKey>::type, std::allocator<std::common_type<CPubKey>::type>> Vector<CPubKey>(CPubKey&&) Line | Count | Source | 24 | 1.88k | { | 25 | 1.88k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.88k | 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.88k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.88k | return ret; | 30 | 1.88k | } |
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.81k | { | 25 | 3.81k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.81k | 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.81k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.81k | return ret; | 30 | 3.81k | } |
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.90k | { | 25 | 1.90k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.90k | 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.90k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.90k | return ret; | 30 | 1.90k | } |
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.64k | { | 25 | 7.64k | std::vector<std::common_type_t<Args...>> ret; | 26 | 7.64k | 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.64k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 7.64k | return ret; | 30 | 7.64k | } |
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 | 126 | { | 25 | 126 | std::vector<std::common_type_t<Args...>> ret; | 26 | 126 | 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 | 126 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 126 | return ret; | 30 | 126 | } |
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.68k | { | 25 | 3.68k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.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 | 3.68k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.68k | return ret; | 30 | 3.68k | } |
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 | 354k | { | 25 | 354k | std::vector<std::common_type_t<Args...>> ret; | 26 | 354k | 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 | 354k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 354k | return ret; | 30 | 354k | } |
std::vector<std::common_type<CScript>::type, std::allocator<std::common_type<CScript>::type>> Vector<CScript>(CScript&&) Line | Count | Source | 24 | 699k | { | 25 | 699k | std::vector<std::common_type_t<Args...>> ret; | 26 | 699k | 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 | 699k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 699k | return ret; | 30 | 699k | } |
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 | 42.7k | { | 25 | 42.7k | std::vector<std::common_type_t<Args...>> ret; | 26 | 42.7k | 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 | 42.7k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 42.7k | return ret; | 30 | 42.7k | } |
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 | 784 | { | 25 | 784 | std::vector<std::common_type_t<Args...>> ret; | 26 | 784 | 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 | 784 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 784 | return ret; | 30 | 784 | } |
std::vector<std::common_type<XOnlyPubKey>::type, std::allocator<std::common_type<XOnlyPubKey>::type>> Vector<XOnlyPubKey>(XOnlyPubKey&&) Line | Count | Source | 24 | 2.48k | { | 25 | 2.48k | std::vector<std::common_type_t<Args...>> ret; | 26 | 2.48k | 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 | 2.48k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 2.48k | return ret; | 30 | 2.48k | } |
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 | 6.26M | { | 25 | 6.26M | std::vector<std::common_type_t<Args...>> ret; | 26 | 6.26M | 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 | 6.26M | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 6.26M | return ret; | 30 | 6.26M | } |
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 | 537 | { | 25 | 537 | std::vector<std::common_type_t<Args...>> ret; | 26 | 537 | 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 | 537 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 537 | return ret; | 30 | 537 | } |
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 | 87.6M | { |
36 | 87.6M | v1.reserve(v1.size() + v2.size()); |
37 | 87.6M | for (auto& arg : v2) { |
38 | 44.3M | v1.push_back(std::move(arg)); |
39 | 44.3M | } |
40 | 87.6M | return v1; |
41 | 87.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 | 671 | { | 36 | 671 | v1.reserve(v1.size() + v2.size()); | 37 | 671 | for (auto& arg : v2) { | 38 | 671 | v1.push_back(std::move(arg)); | 39 | 671 | } | 40 | 671 | return v1; | 41 | 671 | } |
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 | 33.9k | { | 36 | 33.9k | v1.reserve(v1.size() + v2.size()); | 37 | 129k | for (auto& arg : v2) { | 38 | 129k | v1.push_back(std::move(arg)); | 39 | 129k | } | 40 | 33.9k | return v1; | 41 | 33.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.27k | { | 36 | 8.27k | v1.reserve(v1.size() + v2.size()); | 37 | 19.6k | for (auto& arg : v2) { | 38 | 19.6k | v1.push_back(std::move(arg)); | 39 | 19.6k | } | 40 | 8.27k | return v1; | 41 | 8.27k | } |
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 | 45 | { | 36 | 45 | v1.reserve(v1.size() + v2.size()); | 37 | 123 | for (auto& arg : v2) { | 38 | 123 | v1.push_back(std::move(arg)); | 39 | 123 | } | 40 | 45 | return v1; | 41 | 45 | } |
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 | 87.6M | { | 36 | 87.6M | v1.reserve(v1.size() + v2.size()); | 37 | 87.6M | for (auto& arg : v2) { | 38 | 44.1M | v1.push_back(std::move(arg)); | 39 | 44.1M | } | 40 | 87.6M | return v1; | 41 | 87.6M | } |
|
42 | | |
43 | | /** Concatenate two vectors. */ |
44 | | template<typename V> |
45 | | inline V Cat(V v1, const V& v2) |
46 | 688 | { |
47 | 688 | v1.reserve(v1.size() + v2.size()); |
48 | 688 | for (const auto& arg : v2) { |
49 | 31 | v1.push_back(arg); |
50 | 31 | } |
51 | 688 | return v1; |
52 | 688 | } 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 | 686 | { | 47 | 686 | v1.reserve(v1.size() + v2.size()); | 48 | 686 | for (const auto& arg : v2) { | 49 | 26 | v1.push_back(arg); | 50 | 26 | } | 51 | 686 | return v1; | 52 | 686 | } |
|
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.03M | { |
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.03M | V{}.swap(v); |
70 | 1.03M | } void ClearShrink<std::vector<unsigned char, std::allocator<unsigned char>>>(std::vector<unsigned char, std::allocator<unsigned char>>&) Line | Count | Source | 57 | 350k | { | 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 | 350k | V{}.swap(v); | 70 | 350k | } |
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 | 11 | { | 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 | 11 | V{}.swap(v); | 70 | 11 | } |
void ClearShrink<std::deque<CompressedHeader, std::allocator<CompressedHeader>>>(std::deque<CompressedHeader, std::allocator<CompressedHeader>>&) Line | Count | Source | 57 | 11 | { | 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 | 11 | V{}.swap(v); | 70 | 11 | } |
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 | 685k | { | 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 | 685k | V{}.swap(v); | 70 | 685k | } |
|
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 |