aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/message.cpp2
-rw-r--r--src/util/time.h2
-rw-r--r--src/util/vector.h31
3 files changed, 32 insertions, 3 deletions
diff --git a/src/util/message.cpp b/src/util/message.cpp
index ec845aeffb..1afb28cc10 100644
--- a/src/util/message.cpp
+++ b/src/util/message.cpp
@@ -47,7 +47,7 @@ MessageVerificationResult MessageVerify(
return MessageVerificationResult::ERR_PUBKEY_NOT_RECOVERED;
}
- if (!(CTxDestination(PKHash(pubkey)) == destination)) {
+ if (!(PKHash(pubkey) == *std::get_if<PKHash>(&destination))) {
return MessageVerificationResult::ERR_NOT_SIGNED;
}
diff --git a/src/util/time.h b/src/util/time.h
index b6aab615ba..6aa776137c 100644
--- a/src/util/time.h
+++ b/src/util/time.h
@@ -6,8 +6,6 @@
#ifndef BITCOIN_UTIL_TIME_H
#define BITCOIN_UTIL_TIME_H
-#include <compat/compat.h>
-
#include <chrono> // IWYU pragma: export
#include <cstdint>
#include <string>
diff --git a/src/util/vector.h b/src/util/vector.h
index 9b9218e54f..1513562f1b 100644
--- a/src/util/vector.h
+++ b/src/util/vector.h
@@ -5,7 +5,9 @@
#ifndef BITCOIN_UTIL_VECTOR_H
#define BITCOIN_UTIL_VECTOR_H
+#include <functional>
#include <initializer_list>
+#include <optional>
#include <type_traits>
#include <utility>
#include <vector>
@@ -49,4 +51,33 @@ inline V Cat(V v1, const V& v2)
return v1;
}
+/** Clear a vector (or std::deque) and release its allocated memory. */
+template<typename V>
+inline void ClearShrink(V& v) noexcept
+{
+ // There are various ways to clear a vector and release its memory:
+ //
+ // 1. V{}.swap(v)
+ // 2. v = V{}
+ // 3. v = {}; v.shrink_to_fit();
+ // 4. v.clear(); v.shrink_to_fit();
+ //
+ // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit()
+ // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding
+ // request. Therefore, we use method (1).
+
+ V{}.swap(v);
+}
+
+template<typename V, typename L>
+inline std::optional<V> FindFirst(const std::vector<V>& vec, const L fnc)
+{
+ for (const auto& el : vec) {
+ if (fnc(el)) {
+ return el;
+ }
+ }
+ return std::nullopt;
+}
+
#endif // BITCOIN_UTIL_VECTOR_H