UniValue: add reserve member function

- Only reserve keys when the typ is of `VOBJ`.
This commit is contained in:
ismaelsadeeq 2024-10-28 13:02:34 +01:00
parent bd461195f4
commit 6a506d5c37
2 changed files with 9 additions and 0 deletions

View File

@ -70,6 +70,8 @@ public:
size_t size() const { return values.size(); }
void reserve(size_t new_cap);
void getObjMap(std::map<std::string,UniValue>& kv) const;
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes) const;
const UniValue& operator[](const std::string& key) const;

View File

@ -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);
}
}