aboutsummaryrefslogtreecommitdiff
path: root/src/univalue
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-03-03 15:23:10 +0100
committerfanquake <fanquake@gmail.com>2023-03-03 15:23:43 +0100
commit3b88c8502534f0dc94e0abcb04ffa80ba8bd7f01 (patch)
treeef9762eee94274f414ee8c5205a674cab7576580 /src/univalue
parenta12b27a2a6dafe12fbf59815b88f2404617625d6 (diff)
parent545ff924ab6303ffabd91fdfc4f0a4962daf133c (diff)
Merge bitcoin/bitcoin#26612: refactor: RPC: pass named argument value as string_view
545ff924ab6303ffabd91fdfc4f0a4962daf133c refactor: use string_view for RPC named argument values (stickies-v) 7727603e44f8f674e0fc8389e78047e2b56e6052 refactor: reduce unnecessary complexity in ParseNonRFCJSONValue (stickies-v) 1d02e599012721549d4c20b1b37fcc5ee7b961b6 test: add cases to JSON parsing (stickies-v) Pull request description: Inspired by MarcoFalke's [comment](https://github.com/bitcoin/bitcoin/pull/26506#discussion_r1036149426). Main purpose of this PR is to minimize copying (potentially large) RPC named arguments when calling `.substr()` by using `std::string_view` instead of `std::string`. Furthermore, cleans up the code by removing unnecessary complexity in `ParseNonRFCJSONValue()` (done first to avoid refactoring required to concatenate `string` and `string_view`), updates some naming and adds a few test cases. Should not introduce any behaviour change. ## Questions - ~Was there actually any merit to `ParseNonRFCJSONValue()` surrounding the value with brackets and then parsing it as an array? I don't see it, and the new approach doesn't fail any tests. Still a bit suspicious about it though.~ - Cleared up by https://github.com/bitcoin/bitcoin/pull/26506#pullrequestreview-1211984059 - If there are no objections to 7727603e44f8f674e0fc8389e78047e2b56e6052, I think we should follow up with a PR to rename `ParseNonRFCJSONValue()` to a local `Parse()` helper function (that throws if invalid), remove it from `client.h` and merge the test coverage we currently have on `ParseNonRFCJSONValue()` with the coverage we have on `UniValue::read()`. ACKs for top commit: ryanofsky: Code review ACK 545ff924ab6303ffabd91fdfc4f0a4962daf133c MarcoFalke: review ACK 545ff924ab6303ffabd91fdfc4f0a4962daf133c 📻 Tree-SHA512: b1c89fb010ac9c3054b023cac1acbba2a539a09cf39a7baffbd7f7571ee268d5a6d98701c7ac10d68a814526e8fd0fe96ac1d1fb072f272033e415b753f64a5c
Diffstat (limited to 'src/univalue')
-rw-r--r--src/univalue/include/univalue.h5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h
index 16853260b8..d501c3fb69 100644
--- a/src/univalue/include/univalue.h
+++ b/src/univalue/include/univalue.h
@@ -12,6 +12,7 @@
#include <map>
#include <stdexcept>
#include <string>
+#include <string_view>
#include <type_traits>
#include <vector>
@@ -95,9 +96,7 @@ public:
bool read(const char *raw, size_t len);
bool read(const char *raw) { return read(raw, strlen(raw)); }
- bool read(const std::string& rawStr) {
- return read(rawStr.data(), rawStr.size());
- }
+ bool read(std::string_view raw) { return read(raw.data(), raw.size()); }
private:
UniValue::VType typ;