Skip to content

Commit 6a506d5

Browse files
committed
UniValue: add reserve member function
- Only reserve keys when the typ is of `VOBJ`.
1 parent bd46119 commit 6a506d5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/univalue/include/univalue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class UniValue {
7070

7171
size_t size() const { return values.size(); }
7272

73+
void reserve(size_t new_cap);
74+
7375
void getObjMap(std::map<std::string,UniValue>& kv) const;
7476
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes) const;
7577
const UniValue& operator[](const std::string& key) const;

src/univalue/lib/univalue.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,10 @@ const UniValue& UniValue::find_value(std::string_view key) const
240240
return NullUniValue;
241241
}
242242

243+
void UniValue::reserve(size_t new_cap)
244+
{
245+
values.reserve(new_cap);
246+
if (typ == VOBJ) {
247+
keys.reserve(new_cap);
248+
}
249+
}

0 commit comments

Comments
 (0)