Skip to content

Commit 3f03bfd

Browse files
authored
Merge pull request bitcoin#27 from laanwj/2016_09_const_refs
Return const references from getKeys, getValues, get_str
2 parents cedda14 + 5668ca3 commit 3f03bfd

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include/univalue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ class UniValue {
142142
public:
143143
// Strict type-specific getters, these throw std::runtime_error if the
144144
// value is of unexpected type
145-
std::vector<std::string> getKeys() const;
146-
std::vector<UniValue> getValues() const;
145+
const std::vector<std::string>& getKeys() const;
146+
const std::vector<UniValue>& getValues() const;
147147
bool get_bool() const;
148-
std::string get_str() const;
148+
const std::string& get_str() const;
149149
int get_int() const;
150150
int64_t get_int64() const;
151151
double get_real() const;

lib/univalue.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ const UniValue& find_value(const UniValue& obj, const std::string& name)
283283
return NullUniValue;
284284
}
285285

286-
std::vector<std::string> UniValue::getKeys() const
286+
const std::vector<std::string>& UniValue::getKeys() const
287287
{
288288
if (typ != VOBJ)
289289
throw std::runtime_error("JSON value is not an object as expected");
290290
return keys;
291291
}
292292

293-
std::vector<UniValue> UniValue::getValues() const
293+
const std::vector<UniValue>& UniValue::getValues() const
294294
{
295295
if (typ != VOBJ && typ != VARR)
296296
throw std::runtime_error("JSON value is not an object or array as expected");
@@ -304,7 +304,7 @@ bool UniValue::get_bool() const
304304
return getBool();
305305
}
306306

307-
std::string UniValue::get_str() const
307+
const std::string& UniValue::get_str() const
308308
{
309309
if (typ != VSTR)
310310
throw std::runtime_error("JSON value is not a string as expected");

0 commit comments

Comments
 (0)