mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-02 17:24:58 +02: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:
@@ -16,6 +16,7 @@
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -91,7 +92,7 @@ std::string InvalidEstimateModeErrorMessage()
|
||||
return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\"";
|
||||
}
|
||||
|
||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode)
|
||||
bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode& fee_estimate_mode)
|
||||
{
|
||||
auto searchkey = ToUpper(mode_string);
|
||||
for (const auto& pair : FeeModeMap()) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#define BITCOIN_COMMON_MESSAGES_H
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
struct bilingual_str;
|
||||
|
||||
@@ -23,7 +24,7 @@ enum class TransactionError;
|
||||
|
||||
namespace common {
|
||||
enum class PSBTError;
|
||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode);
|
||||
bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode& fee_estimate_mode);
|
||||
std::string StringForFeeReason(FeeReason reason);
|
||||
std::string FeeModes(const std::string& delimiter);
|
||||
std::string FeeModeInfo(std::pair<std::string, FeeEstimateMode>& mode);
|
||||
|
||||
Reference in New Issue
Block a user