Skip to content

Commit

Permalink
UniValue: add reserve member function
Browse files Browse the repository at this point in the history
- Only reserve keys when the typ is of `VOBJ`.
  • Loading branch information
ismaelsadeeq committed Oct 30, 2024
1 parent ffe4261 commit 952463c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/univalue/include/univalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class UniValue {

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;
Expand Down
7 changes: 7 additions & 0 deletions src/univalue/lib/univalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 952463c

Please sign in to comment.