From 6a506d5c37d1cb179b4e818dfbeaff5834420a33 Mon Sep 17 00:00:00 2001 From: ismaelsadeeq Date: Mon, 28 Oct 2024 13:02:34 +0100 Subject: [PATCH] UniValue: add reserve member function - Only reserve keys when the typ is of `VOBJ`. --- src/univalue/include/univalue.h | 2 ++ src/univalue/lib/univalue.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h index da121575554..0e5404eb1df 100644 --- a/src/univalue/include/univalue.h +++ b/src/univalue/include/univalue.h @@ -70,6 +70,8 @@ public: size_t size() const { return values.size(); } + void reserve(size_t new_cap); + void getObjMap(std::map& kv) const; bool checkObject(const std::map& memberTypes) const; const UniValue& operator[](const std::string& key) const; diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp index 656d2e82030..4d37c81fe87 100644 --- a/src/univalue/lib/univalue.cpp +++ b/src/univalue/lib/univalue.cpp @@ -240,3 +240,10 @@ const UniValue& UniValue::find_value(std::string_view key) const return NullUniValue; } +void UniValue::reserve(size_t new_cap) +{ + values.reserve(new_cap); + if (typ == VOBJ) { + keys.reserve(new_cap); + } +}