Use std::string_view

This commit is contained in:
Bart
2026-03-02 11:58:57 -05:00
parent 6c3b00c342
commit b117ecc6a2
5 changed files with 17 additions and 9 deletions

View File

@@ -231,4 +231,11 @@ makeSlice(std::basic_string<char, Traits, Alloc> const& s)
return Slice(s.data(), s.size());
}
template <class Traits>
Slice
makeSlice(std::basic_string_view<char, Traits> const& s)
{
return Slice(s.data(), s.size());
}
} // namespace xrpl

View File

@@ -9,6 +9,7 @@
#include <mutex>
#include <set>
#include <string_view>
#include <utility>
namespace xrpl {
@@ -131,16 +132,16 @@ private:
processData(std::shared_ptr<Peer> peer, protocol::TMLedgerData& data);
bool
takeHeader(std::string const& data);
takeHeader(std::string_view data);
void
receiveNode(protocol::TMLedgerData& packet, SHAMapAddNode& san);
bool
takeTxRootNode(std::string const& data, SHAMapAddNode& san);
takeTxRootNode(std::string_view data, SHAMapAddNode& san);
bool
takeAsRootNode(std::string const& data, SHAMapAddNode& san);
takeAsRootNode(std::string_view data, SHAMapAddNode& san);
std::vector<uint256>
neededTxHashes(int max, SHAMapSyncFilter* filter) const;

View File

@@ -755,7 +755,7 @@ InboundLedger::filterNodes(
*/
// data must not have hash prefix
bool
InboundLedger::takeHeader(std::string const& data)
InboundLedger::takeHeader(std::string_view data)
{
// Return value: true=normal, false=bad data
JLOG(journal_.trace()) << "got header acquiring ledger " << hash_;
@@ -903,7 +903,7 @@ InboundLedger::receiveNode(protocol::TMLedgerData& packet, SHAMapAddNode& san)
Call with a lock
*/
bool
InboundLedger::takeAsRootNode(std::string const& data, SHAMapAddNode& san)
InboundLedger::takeAsRootNode(std::string_view data, SHAMapAddNode& san)
{
if (failed_ || mHaveState)
{
@@ -937,7 +937,7 @@ InboundLedger::takeAsRootNode(std::string const& data, SHAMapAddNode& san)
Call with a lock
*/
bool
InboundLedger::takeTxRootNode(std::string const& data, SHAMapAddNode& san)
InboundLedger::takeTxRootNode(std::string_view data, SHAMapAddNode& san)
{
if (failed_ || mHaveTransactions)
{

View File

@@ -28,7 +28,7 @@ validateLedgerNode(protocol::TMLedgerNode const& ledger_node)
}
std::optional<intr_ptr::SharedPtr<SHAMapTreeNode>>
getTreeNode(std::string const& data)
getTreeNode(std::string_view data)
{
auto const slice = makeSlice(data);
try

View File

@@ -5,7 +5,7 @@
#include <xrpl/shamap/SHAMapTreeNode.h>
#include <optional>
#include <string>
#include <string_view>
namespace protocol {
class TMLedgerNode;
@@ -42,7 +42,7 @@ validateLedgerNode(protocol::TMLedgerNode const& ledger_node);
* deserialization fails.
*/
[[nodiscard]] std::optional<intr_ptr::SharedPtr<SHAMapTreeNode>>
getTreeNode(std::string const& data);
getTreeNode(std::string_view data);
/**
* @brief Extracts or reconstructs the SHAMapNodeID from a ledger node proto message.