/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.09M | { |
25 | 8.09M | std::vector<std::common_type_t<Args...>> ret; |
26 | 8.09M | 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.09M | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; |
29 | 8.09M | return ret; |
30 | 8.09M | } 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.80k | { | 25 | 1.80k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.80k | 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.80k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.80k | return ret; | 30 | 1.80k | } |
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.43k | { | 25 | 4.43k | std::vector<std::common_type_t<Args...>> ret; | 26 | 4.43k | 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.43k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 4.43k | return ret; | 30 | 4.43k | } |
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.82k | { | 25 | 9.82k | std::vector<std::common_type_t<Args...>> ret; | 26 | 9.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 | 9.82k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 9.82k | return ret; | 30 | 9.82k | } |
std::vector<std::common_type<CPubKey>::type, std::allocator<std::common_type<CPubKey>::type>> Vector<CPubKey>(CPubKey&&) Line | Count | Source | 24 | 1.77k | { | 25 | 1.77k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.77k | 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.77k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.77k | return ret; | 30 | 1.77k | } |
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.93k | { | 25 | 3.93k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.93k | 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.93k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.93k | return ret; | 30 | 3.93k | } |
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.96k | { | 25 | 1.96k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.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 | 1.96k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.96k | return ret; | 30 | 1.96k | } |
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.59k | { | 25 | 7.59k | std::vector<std::common_type_t<Args...>> ret; | 26 | 7.59k | 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.59k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 7.59k | return ret; | 30 | 7.59k | } |
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 | 110 | { | 25 | 110 | std::vector<std::common_type_t<Args...>> ret; | 26 | 110 | 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 | 110 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 110 | return ret; | 30 | 110 | } |
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.67k | { | 25 | 3.67k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.67k | 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.67k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.67k | return ret; | 30 | 3.67k | } |
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 | 43.5k | { | 25 | 43.5k | std::vector<std::common_type_t<Args...>> ret; | 26 | 43.5k | 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 | 43.5k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 43.5k | return ret; | 30 | 43.5k | } |
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.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<unsigned int>::type, std::allocator<std::common_type<unsigned int>::type>> Vector<unsigned int>(unsigned int&&) Line | Count | Source | 24 | 1.60k | { | 25 | 1.60k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.60k | 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.60k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.60k | return ret; | 30 | 1.60k | } |
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.16k | { | 25 | 1.16k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.16k | 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.16k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.16k | return ret; | 30 | 1.16k | } |
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 | 116 | { | 25 | 116 | std::vector<std::common_type_t<Args...>> ret; | 26 | 116 | 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 | 116 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 116 | return ret; | 30 | 116 | } |
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 | 801 | { | 25 | 801 | std::vector<std::common_type_t<Args...>> ret; | 26 | 801 | 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 | 801 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 801 | return ret; | 30 | 801 | } |
std::vector<std::common_type<XOnlyPubKey>::type, std::allocator<std::common_type<XOnlyPubKey>::type>> Vector<XOnlyPubKey>(XOnlyPubKey&&) Line | Count | Source | 24 | 2.40k | { | 25 | 2.40k | std::vector<std::common_type_t<Args...>> ret; | 26 | 2.40k | 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.40k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 2.40k | return ret; | 30 | 2.40k | } |
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.27M | { | 25 | 5.27M | std::vector<std::common_type_t<Args...>> ret; | 26 | 5.27M | 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.27M | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 5.27M | return ret; | 30 | 5.27M | } |
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 | 521 | { | 25 | 521 | std::vector<std::common_type_t<Args...>> ret; | 26 | 521 | 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 | 521 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 521 | return ret; | 30 | 521 | } |
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 | 90.6M | { |
36 | 90.6M | v1.reserve(v1.size() + v2.size()); |
37 | 90.6M | for (auto& arg : v2) { |
38 | 45.7M | v1.push_back(std::move(arg)); |
39 | 45.7M | } |
40 | 90.6M | return v1; |
41 | 90.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 | 668 | { | 36 | 668 | v1.reserve(v1.size() + v2.size()); | 37 | 668 | for (auto& arg : v2) { | 38 | 668 | v1.push_back(std::move(arg)); | 39 | 668 | } | 40 | 668 | return v1; | 41 | 668 | } |
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.0k | { | 36 | 33.0k | v1.reserve(v1.size() + v2.size()); | 37 | 124k | for (auto& arg : v2) { | 38 | 124k | v1.push_back(std::move(arg)); | 39 | 124k | } | 40 | 33.0k | return v1; | 41 | 33.0k | } |
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 | 4.10k | { | 36 | 4.10k | v1.reserve(v1.size() + v2.size()); | 37 | 16.4k | for (auto& arg : v2) { | 38 | 16.4k | v1.push_back(std::move(arg)); | 39 | 16.4k | } | 40 | 4.10k | return v1; | 41 | 4.10k | } |
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 | 90.6M | { | 36 | 90.6M | v1.reserve(v1.size() + v2.size()); | 37 | 90.6M | for (auto& arg : v2) { | 38 | 45.6M | v1.push_back(std::move(arg)); | 39 | 45.6M | } | 40 | 90.6M | return v1; | 41 | 90.6M | } |
|
42 | | |
43 | | /** Concatenate two vectors. */ |
44 | | template<typename V> |
45 | | inline V Cat(V v1, const V& v2) |
46 | 685 | { |
47 | 685 | v1.reserve(v1.size() + v2.size()); |
48 | 685 | for (const auto& arg : v2) { |
49 | 31 | v1.push_back(arg); |
50 | 31 | } |
51 | 685 | return v1; |
52 | 685 | } 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 | 683 | { | 47 | 683 | v1.reserve(v1.size() + v2.size()); | 48 | 683 | for (const auto& arg : v2) { | 49 | 26 | v1.push_back(arg); | 50 | 26 | } | 51 | 683 | return v1; | 52 | 683 | } |
|
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.05M | { |
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.05M | V{}.swap(v); |
70 | 1.05M | } 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 | 695k | { | 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 | 695k | V{}.swap(v); | 70 | 695k | } |
|
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 |