Skip to content

Commit fa548ac

Browse files
author
MarcoFalke
committed
Add UniValue::find_value method
1 parent fc06881 commit fa548ac

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/univalue/include/univalue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class UniValue {
123123
const UniValue& get_array() const;
124124

125125
enum VType type() const { return getType(); }
126-
friend const UniValue& find_value( const UniValue& obj, const std::string& name);
126+
const UniValue& find_value(std::string_view key) const;
127127
};
128128

129129
template <class It>
@@ -201,6 +201,6 @@ static inline bool json_isspace(int ch)
201201

202202
extern const UniValue NullUniValue;
203203

204-
const UniValue& find_value( const UniValue& obj, const std::string& name);
204+
inline const UniValue& find_value(const UniValue& obj, const std::string& name) { return obj.find_value(name); }
205205

206206
#endif // BITCOIN_UNIVALUE_INCLUDE_UNIVALUE_H

src/univalue/lib/univalue.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,13 @@ const char *uvTypeName(UniValue::VType t)
230230
return nullptr;
231231
}
232232

233-
const UniValue& find_value(const UniValue& obj, const std::string& name)
233+
const UniValue& UniValue::find_value(std::string_view key) const
234234
{
235-
for (unsigned int i = 0; i < obj.keys.size(); i++)
236-
if (obj.keys[i] == name)
237-
return obj.values.at(i);
238-
235+
for (unsigned int i = 0; i < keys.size(); ++i) {
236+
if (keys[i] == key) {
237+
return values.at(i);
238+
}
239+
}
239240
return NullUniValue;
240241
}
241242

0 commit comments

Comments
 (0)