/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 | 7.12M | { |
25 | 7.12M | std::vector<std::common_type_t<Args...>> ret; |
26 | 7.12M | 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.12M | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; |
29 | 7.12M | return ret; |
30 | 7.12M | } 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 | 490k | { | 25 | 490k | std::vector<std::common_type_t<Args...>> ret; | 26 | 490k | 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 | 490k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 490k | return ret; | 30 | 490k | } |
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 | 9.80k | { | 25 | 9.80k | std::vector<std::common_type_t<Args...>> ret; | 26 | 9.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 | 9.80k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 9.80k | return ret; | 30 | 9.80k | } |
std::vector<std::common_type<CPubKey>::type, std::allocator<std::common_type<CPubKey>::type>> Vector<CPubKey>(CPubKey&&) Line | Count | Source | 24 | 1.75k | { | 25 | 1.75k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.75k | 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.75k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.75k | return ret; | 30 | 1.75k | } |
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.83k | { | 25 | 3.83k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.83k | 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.83k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.83k | return ret; | 30 | 3.83k | } |
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.58k | { | 25 | 7.58k | std::vector<std::common_type_t<Args...>> ret; | 26 | 7.58k | 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.58k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 7.58k | return ret; | 30 | 7.58k | } |
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 | 104 | { | 25 | 104 | std::vector<std::common_type_t<Args...>> ret; | 26 | 104 | 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 | 104 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 104 | return ret; | 30 | 104 | } |
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.73k | { | 25 | 3.73k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.73k | 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.73k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.73k | return ret; | 30 | 3.73k | } |
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 | 356k | { | 25 | 356k | std::vector<std::common_type_t<Args...>> ret; | 26 | 356k | 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 | 356k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 356k | return ret; | 30 | 356k | } |
std::vector<std::common_type<CScript>::type, std::allocator<std::common_type<CScript>::type>> Vector<CScript>(CScript&&) Line | Count | Source | 24 | 716k | { | 25 | 716k | std::vector<std::common_type_t<Args...>> ret; | 26 | 716k | 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 | 716k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 716k | return ret; | 30 | 716k | } |
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.6k | { | 25 | 36.6k | std::vector<std::common_type_t<Args...>> ret; | 26 | 36.6k | 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.6k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 36.6k | return ret; | 30 | 36.6k | } |
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.92k | { | 25 | 1.92k | std::vector<std::common_type_t<Args...>> ret; | 26 | 1.92k | 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.92k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 1.92k | return ret; | 30 | 1.92k | } |
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 | 808 | { | 25 | 808 | std::vector<std::common_type_t<Args...>> ret; | 26 | 808 | 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 | 808 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 808 | return ret; | 30 | 808 | } |
std::vector<std::common_type<XOnlyPubKey>::type, std::allocator<std::common_type<XOnlyPubKey>::type>> Vector<XOnlyPubKey>(XOnlyPubKey&&) Line | Count | Source | 24 | 3.43k | { | 25 | 3.43k | std::vector<std::common_type_t<Args...>> ret; | 26 | 3.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 | 3.43k | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 3.43k | return ret; | 30 | 3.43k | } |
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 | 4.28M | { | 25 | 4.28M | std::vector<std::common_type_t<Args...>> ret; | 26 | 4.28M | 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.28M | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 4.28M | return ret; | 30 | 4.28M | } |
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 | 851 | { | 25 | 851 | std::vector<std::common_type_t<Args...>> ret; | 26 | 851 | 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 | 851 | (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...}; | 29 | 851 | return ret; | 30 | 851 | } |
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.8M | v1.push_back(std::move(arg)); |
39 | 45.8M | } |
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 | 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.5k | { | 36 | 34.5k | v1.reserve(v1.size() + v2.size()); | 37 | 130k | for (auto& arg : v2) { | 38 | 130k | v1.push_back(std::move(arg)); | 39 | 130k | } | 40 | 34.5k | return v1; | 41 | 34.5k | } |
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.32k | { | 36 | 8.32k | 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.32k | return v1; | 41 | 8.32k | } |
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 | 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 | 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.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 | 336k | { | 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 | 336k | V{}.swap(v); | 70 | 336k | } |
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 | 698k | { | 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 | 698k | V{}.swap(v); | 70 | 698k | } |
|
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 |