mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
Merge bitcoin/bitcoin#32983: rpc: refactor: use string_view in Arg/MaybeArg
b63428ac9crpc: refactor: use more (Maybe)Arg<std::string_view> (stickies-v)037830ca0drefactor: increase string_view usage (stickies-v)b3bf18f0barpc: refactor: use string_view in Arg/MaybeArg (stickies-v) Pull request description: The `RPCHelpMan::{Arg,MaybeArg}` helpers avoid copying (potentially) large strings by returning them as `const std::string*` (`MaybeArg`) or `const std::string&` (`Arg`). For `MaybeArg`, this has the not-so-nice effect that users need to deal with raw pointers, potentially also requiring new functions (e.g. [`EnsureUniqueWalletName` ](d127b25199 (diff-d8bfcfbdd5fa7d5c52d38c1fe5eeac9ce5c5a794cdfaf683585140fa70a32374R32))) with raw pointers being implemented. This PR aims to improve on this by returning a trivially copyable `std::string_view` (`Arg`) or `std::optional<std::string_view>` (`MaybeArg`), modernizing the interface without introducing any additional copying overhead. In doing so, it also generalizes whether we return by value or by pointer/reference using `std::is_trivially_copyable_v` instead of defining the types manually. In cases where functions currently take a `const std::string&` and it would be too much work / touching consensus logic to update them (`signmessage.cpp`), a `std::string` copy is made (which was already happening anyway). The last 2 commits increase usage of the `{Arg,MaybeArg}<std::string_view>` helpers, and could be dropped/pruned if anything turns out to be controversial - I just think it's a nice little cleanup. ACKs for top commit: maflcko: re-ACKb63428ac9c🎉 achow101: ACKb63428ac9cpablomartin4btc: re-ACK [b63428a](b63428ac9c) w0xlt: reACKb63428ac9cTree-SHA512: b4942c353a1658c22a88d8c9b402c288ad35265a3b88aa2072b1f9b6d921cd073194ed4b00b807cb48ca440f47c87ef3d8e0dd1a5d814be58fc7743f26288277
This commit is contained in:
@@ -2730,13 +2730,12 @@ bool CheckChecksum(std::span<const char>& sp, bool require_checksum, std::string
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Descriptor>> Parse(const std::string& descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum)
|
||||
std::vector<std::unique_ptr<Descriptor>> Parse(std::span<const char> descriptor, FlatSigningProvider& out, std::string& error, bool require_checksum)
|
||||
{
|
||||
std::span<const char> sp{descriptor};
|
||||
if (!CheckChecksum(sp, require_checksum, error)) return {};
|
||||
if (!CheckChecksum(descriptor, require_checksum, error)) return {};
|
||||
uint32_t key_exp_index = 0;
|
||||
auto ret = ParseScript(key_exp_index, sp, ParseScriptContext::TOP, out, error);
|
||||
if (sp.size() == 0 && !ret.empty()) {
|
||||
auto ret = ParseScript(key_exp_index, descriptor, ParseScriptContext::TOP, out, error);
|
||||
if (descriptor.empty() && !ret.empty()) {
|
||||
std::vector<std::unique_ptr<Descriptor>> descs;
|
||||
descs.reserve(ret.size());
|
||||
for (auto& r : ret) {
|
||||
|
||||
Reference in New Issue
Block a user