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
) 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.