From e65e61c812df90a56e3ce4a8e76c4b746766f387 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 28 Aug 2019 15:12:51 -0700 Subject: [PATCH] Add some general std::vector utility functions Added are: * Vector(arg1,arg2,arg3,...) constructs a vector with the specified arguments as elements. The vector's type is derived from the arguments. If some of the arguments are rvalue references, they will be moved into place rather than copied (which can't be achieved using list initialization). * Cat(vector1,vector2) returns a concatenation of the two vectors, efficiently moving elements when relevant. Vector generalizes (and replaces) the Singleton function in src/descriptor.cpp, and Cat replaces the Cat function in bech32.cpp --- src/Makefile.am | 1 + src/bech32.cpp | 8 +----- src/outputtype.cpp | 6 +++-- src/script/descriptor.cpp | 36 +++++++++++---------------- src/txdb.cpp | 3 ++- src/util/vector.h | 51 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 32 deletions(-) create mode 100644 src/util/vector.h diff --git a/src/Makefile.am b/src/Makefile.am index eec84122aee..d50524a8ae7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -220,6 +220,7 @@ BITCOIN_CORE_H = \ util/translation.h \ util/url.h \ util/validation.h \ + util/vector.h \ validation.h \ validationinterface.h \ versionbits.h \ diff --git a/src/bech32.cpp b/src/bech32.cpp index 4c966350b4c..1e0471f1101 100644 --- a/src/bech32.cpp +++ b/src/bech32.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include @@ -26,13 +27,6 @@ const int8_t CHARSET_REV[128] = { 1, 0, 3, 16, 11, 28, 12, 14, 6, 4, 2, -1, -1, -1, -1, -1 }; -/** Concatenate two byte arrays. */ -data Cat(data x, const data& y) -{ - x.insert(x.end(), y.begin(), y.end()); - return x; -} - /** This function will compute what 6 5-bit values to XOR into the last 6 input values, in order to * make the checksum 0. These 6 values are packed together in a single 30-bit integer. The higher * bits correspond to earlier values. */ diff --git a/src/outputtype.cpp b/src/outputtype.cpp index bcaa05f4b67..5cc43898a71 100644 --- a/src/outputtype.cpp +++ b/src/outputtype.cpp @@ -10,6 +10,7 @@ #include