aboutsummaryrefslogtreecommitdiff
path: root/src/univalue/lib/univalue.cpp
diff options
context:
space:
mode:
authorMacroFake <falke.marco@gmail.com>2022-11-14 10:13:50 +0100
committerMacroFake <falke.marco@gmail.com>2022-11-14 10:17:54 +0100
commit59e00c7e03107e7d2582a0c14431bb4e62cccd77 (patch)
tree4442fe7cc1e8891407ec49e4bf39b5bff1670ae8 /src/univalue/lib/univalue.cpp
parent7ef730ca84bd71a06f986ae7070e7b2ac8e47582 (diff)
parentfa095257511e53d7a593c6714724aafb484e6b6f (diff)
downloadbitcoin-59e00c7e03107e7d2582a0c14431bb4e62cccd77.tar.xz
Merge bitcoin/bitcoin#25714: univalue: Avoid std::string copies
fa095257511e53d7a593c6714724aafb484e6b6f univalue: string_view test (MacroFake) 1111c7e3f1f5c550f62016d71ccc518aafd97acf univalue: Avoid std::string copies (MacroFake) Pull request description: This shouldn't matter too much, unless a really large string is pushed into a json struct, but I think it also clarifies the code. ACKs for top commit: martinus: Code review ACK https://github.com/bitcoin/bitcoin/commit/fa095257511e53d7a593c6714724aafb484e6b6f aureleoules: reACK fa095257511e53d7a593c6714724aafb484e6b6f ryanofsky: Code review ACK fa095257511e53d7a593c6714724aafb484e6b6f Tree-SHA512: 74c441912bd0b00cdb9ea7890121f71ae5d62a7594e7d29aa402c9e3f033710c5d3afb27a37c552e6513804b249aa37e375ce013a3db853a25d1fd7b6e6cd3a8
Diffstat (limited to 'src/univalue/lib/univalue.cpp')
-rw-r--r--src/univalue/lib/univalue.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp
index 4448981d3e..5aa39edb75 100644
--- a/src/univalue/lib/univalue.cpp
+++ b/src/univalue/lib/univalue.cpp
@@ -44,15 +44,15 @@ static bool validNumStr(const std::string& s)
return (tt == JTOK_NUMBER);
}
-void UniValue::setNumStr(const std::string& val_)
+void UniValue::setNumStr(std::string str)
{
- if (!validNumStr(val_)) {
- throw std::runtime_error{"The string '" + val_ + "' is not a valid JSON number"};
+ if (!validNumStr(str)) {
+ throw std::runtime_error{"The string '" + str + "' is not a valid JSON number"};
}
clear();
typ = VNUM;
- val = val_;
+ val = std::move(str);
}
void UniValue::setInt(uint64_t val_)
@@ -82,11 +82,11 @@ void UniValue::setFloat(double val_)
return setNumStr(oss.str());
}
-void UniValue::setStr(const std::string& val_)
+void UniValue::setStr(std::string str)
{
clear();
typ = VSTR;
- val = val_;
+ val = std::move(str);
}
void UniValue::setArray()