Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #27 from laanwj/2016_09_const_refs
Browse files Browse the repository at this point in the history
Return const references from getKeys, getValues, get_str
  • Loading branch information
jgarzik authored Sep 26, 2016
2 parents cedda14 + 5668ca3 commit 3f03bfd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions include/univalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ class UniValue {
public:
// Strict type-specific getters, these throw std::runtime_error if the
// value is of unexpected type
std::vector<std::string> getKeys() const;
std::vector<UniValue> getValues() const;
const std::vector<std::string>& getKeys() const;
const std::vector<UniValue>& getValues() const;
bool get_bool() const;
std::string get_str() const;
const std::string& get_str() const;
int get_int() const;
int64_t get_int64() const;
double get_real() const;
Expand Down
6 changes: 3 additions & 3 deletions lib/univalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ const UniValue& find_value(const UniValue& obj, const std::string& name)
return NullUniValue;
}

std::vector<std::string> UniValue::getKeys() const
const std::vector<std::string>& UniValue::getKeys() const
{
if (typ != VOBJ)
throw std::runtime_error("JSON value is not an object as expected");
return keys;
}

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

std::string UniValue::get_str() const
const std::string& UniValue::get_str() const
{
if (typ != VSTR)
throw std::runtime_error("JSON value is not a string as expected");
Expand Down

0 comments on commit 3f03bfd

Please sign in to comment.