From 53c0e7cacedaf71069d5b82c7aa01cfc4b8d21cf Mon Sep 17 00:00:00 2001 From: JCW Date: Fri, 29 Aug 2025 22:59:53 +0100 Subject: [PATCH] Optimisation Signed-off-by: JCW --- include/xrpl/basics/Log.h | 4 ++-- include/xrpl/beast/utility/Journal.h | 6 +++--- include/xrpl/beast/utility/WrappedSink.h | 4 ++-- src/libxrpl/basics/Log.cpp | 8 ++++---- src/libxrpl/beast/utility/beast_Journal.cpp | 10 +++++----- src/test/beast/beast_Journal_test.cpp | 4 ++-- src/test/csf/Sim.h | 4 ++-- src/test/jtx/CaptureLogs.h | 4 ++-- src/test/jtx/CheckMessageLogs.h | 6 +++--- src/test/server/Server_test.cpp | 4 ++-- src/test/unit_test/SuiteJournal.h | 16 ++++++++-------- src/tests/libxrpl/basics/log.cpp | 8 ++++---- 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/include/xrpl/basics/Log.h b/include/xrpl/basics/Log.h index 3b801f4beb..fe61f2c541 100644 --- a/include/xrpl/basics/Log.h +++ b/include/xrpl/basics/Log.h @@ -68,11 +68,11 @@ private: operator=(Sink const&) = delete; void - write(beast::severities::Severity level, std::string const& text) + write(beast::severities::Severity level, std::string&& text) override; void - writeAlways(beast::severities::Severity level, std::string const& text) + writeAlways(beast::severities::Severity level, std::string&& text) override; }; diff --git a/include/xrpl/beast/utility/Journal.h b/include/xrpl/beast/utility/Journal.h index 9e73f279dd..d501ae29f6 100644 --- a/include/xrpl/beast/utility/Journal.h +++ b/include/xrpl/beast/utility/Journal.h @@ -225,7 +225,7 @@ private: severities::Severity severity) const; static std::string - formatLog(std::string const& message); + formatLog(std::string&& message); public: //-------------------------------------------------------------------------- @@ -279,7 +279,7 @@ public: level is below the current threshold(). */ virtual void - write(Severity level, std::string const& text) = 0; + write(Severity level, std::string&& text) = 0; /** Bypass filter and write text to the sink at the specified severity. * Always write the message, but maintain the same formatting as if @@ -289,7 +289,7 @@ public: * @param text Text to write to sink. */ virtual void - writeAlways(Severity level, std::string const& text) = 0; + writeAlways(Severity level, std::string&& text) = 0; private: Severity thresh_; diff --git a/include/xrpl/beast/utility/WrappedSink.h b/include/xrpl/beast/utility/WrappedSink.h index 72dcf4e8f5..ee8641849d 100644 --- a/include/xrpl/beast/utility/WrappedSink.h +++ b/include/xrpl/beast/utility/WrappedSink.h @@ -88,14 +88,14 @@ public: } void - write(beast::severities::Severity level, std::string const& text) override + write(beast::severities::Severity level, std::string&& text) override { using beast::Journal; sink_.write(level, prefix_ + text); } void - writeAlways(severities::Severity level, std::string const& text) override + writeAlways(severities::Severity level, std::string&& text) override { using beast::Journal; sink_.writeAlways(level, prefix_ + text); diff --git a/src/libxrpl/basics/Log.cpp b/src/libxrpl/basics/Log.cpp index a699183221..60d4fadb8b 100644 --- a/src/libxrpl/basics/Log.cpp +++ b/src/libxrpl/basics/Log.cpp @@ -47,20 +47,20 @@ Logs::Sink::Sink( } void -Logs::Sink::write(beast::severities::Severity level, std::string const& text) +Logs::Sink::write(beast::severities::Severity level, std::string&& text) { if (level < threshold()) return; - logs_.write(level, partition_, text, console()); + logs_.write(level, partition_, std::move(text), console()); } void Logs::Sink::writeAlways( beast::severities::Severity level, - std::string const& text) + std::string&& text) { - logs_.write(level, partition_, text, console()); + logs_.write(level, partition_, std::move(text), console()); } //------------------------------------------------------------------------------ diff --git a/src/libxrpl/beast/utility/beast_Journal.cpp b/src/libxrpl/beast/utility/beast_Journal.cpp index 1c5f7ed7df..6aa617722d 100644 --- a/src/libxrpl/beast/utility/beast_Journal.cpp +++ b/src/libxrpl/beast/utility/beast_Journal.cpp @@ -77,12 +77,12 @@ public: } void - write(severities::Severity, std::string const&) override + write(severities::Severity, std::string&&) override { } void - writeAlways(severities::Severity, std::string const&) override + writeAlways(severities::Severity, std::string&&) override { } }; @@ -264,7 +264,7 @@ Journal::initMessageContext( } std::string -Journal::formatLog(std::string const& message) +Journal::formatLog(std::string&& message) { if (!m_jsonLogsEnabled) { @@ -363,13 +363,13 @@ Journal::ScopedStream::ScopedStream( Journal::ScopedStream::~ScopedStream() { - std::string const& s(m_ostream.str()); + std::string s(m_ostream.str()); if (!s.empty()) { if (s == "\n") m_sink.write(m_level, formatLog("")); else - m_sink.write(m_level, formatLog(s)); + m_sink.write(m_level, formatLog(std::move(s))); } } diff --git a/src/test/beast/beast_Journal_test.cpp b/src/test/beast/beast_Journal_test.cpp index 13e2726c89..abd4af4f8d 100644 --- a/src/test/beast/beast_Journal_test.cpp +++ b/src/test/beast/beast_Journal_test.cpp @@ -48,14 +48,14 @@ public: } void - write(severities::Severity level, std::string const&) override + write(severities::Severity level, std::string&&) override { if (level >= threshold()) ++m_count; } void - writeAlways(severities::Severity level, std::string const&) override + writeAlways(severities::Severity level, std::string&&) override { ++m_count; } diff --git a/src/test/csf/Sim.h b/src/test/csf/Sim.h index 0cb052305a..cf4725c709 100644 --- a/src/test/csf/Sim.h +++ b/src/test/csf/Sim.h @@ -49,7 +49,7 @@ public: } void - write(beast::severities::Severity level, std::string const& text) override + write(beast::severities::Severity level, std::string&& text) override { if (level < threshold()) return; @@ -59,7 +59,7 @@ public: } void - writeAlways(beast::severities::Severity level, std::string const& text) + writeAlways(beast::severities::Severity level, std::string&& text) override { std::cout << clock_.now().time_since_epoch().count() << " " << text diff --git a/src/test/jtx/CaptureLogs.h b/src/test/jtx/CaptureLogs.h index a8afb521c3..20bf4dd51a 100644 --- a/src/test/jtx/CaptureLogs.h +++ b/src/test/jtx/CaptureLogs.h @@ -57,7 +57,7 @@ class CaptureLogs : public Logs } void - write(beast::severities::Severity level, std::string const& text) + write(beast::severities::Severity level, std::string&& text) override { std::lock_guard lock(strmMutex_); @@ -65,7 +65,7 @@ class CaptureLogs : public Logs } void - writeAlways(beast::severities::Severity level, std::string const& text) + writeAlways(beast::severities::Severity level, std::string&& text) override { std::lock_guard lock(strmMutex_); diff --git a/src/test/jtx/CheckMessageLogs.h b/src/test/jtx/CheckMessageLogs.h index fd3915440e..12673a8a14 100644 --- a/src/test/jtx/CheckMessageLogs.h +++ b/src/test/jtx/CheckMessageLogs.h @@ -45,7 +45,7 @@ class CheckMessageLogs : public Logs } void - write(beast::severities::Severity level, std::string const& text) + write(beast::severities::Severity level, std::string&& text) override { if (text.find(owner_.msg_) != std::string::npos) @@ -53,10 +53,10 @@ class CheckMessageLogs : public Logs } void - writeAlways(beast::severities::Severity level, std::string const& text) + writeAlways(beast::severities::Severity level, std::string&& text) override { - write(level, text); + write(level, std::move(text)); } }; diff --git a/src/test/server/Server_test.cpp b/src/test/server/Server_test.cpp index fab271ff1c..e87ed738f3 100644 --- a/src/test/server/Server_test.cpp +++ b/src/test/server/Server_test.cpp @@ -89,7 +89,7 @@ public: } void - write(beast::severities::Severity level, std::string const& text) + write(beast::severities::Severity level, std::string&& text) override { if (level < threshold()) @@ -99,7 +99,7 @@ public: } void - writeAlways(beast::severities::Severity level, std::string const& text) + writeAlways(beast::severities::Severity level, std::string&& text) override { suite_.log << text << std::endl; diff --git a/src/test/unit_test/SuiteJournal.h b/src/test/unit_test/SuiteJournal.h index d56c297b0a..f0421080b6 100644 --- a/src/test/unit_test/SuiteJournal.h +++ b/src/test/unit_test/SuiteJournal.h @@ -49,27 +49,27 @@ public: } void - write(beast::severities::Severity level, std::string const& text) override; + write(beast::severities::Severity level, std::string&& text) override; void - writeAlways(beast::severities::Severity level, std::string const& text) + writeAlways(beast::severities::Severity level, std::string&& text) override; }; inline void SuiteJournalSink::write( beast::severities::Severity level, - std::string const& text) + std::string&& text) { // Only write the string if the level at least equals the threshold. if (level >= threshold()) - writeAlways(level, text); + writeAlways(level, std::move(text)); } inline void SuiteJournalSink::writeAlways( beast::severities::Severity level, - std::string const& text) + std::string&& text) { using namespace beast::severities; @@ -137,15 +137,15 @@ public: } void - write(beast::severities::Severity level, std::string const& text) override + write(beast::severities::Severity level, std::string&& text) override { if (level < threshold()) return; - writeAlways(level, text); + writeAlways(level, std::move(text)); } inline void - writeAlways(beast::severities::Severity level, std::string const& text) + writeAlways(beast::severities::Severity level, std::string&& text) override { strm_ << text << std::endl; diff --git a/src/tests/libxrpl/basics/log.cpp b/src/tests/libxrpl/basics/log.cpp index fb634a3a71..de5a2aa5a2 100644 --- a/src/tests/libxrpl/basics/log.cpp +++ b/src/tests/libxrpl/basics/log.cpp @@ -49,14 +49,14 @@ private: operator=(Sink const&) = delete; void - write(beast::severities::Severity level, std::string const& text) + write(beast::severities::Severity level, std::string&& text) override { logs_.logStream_ << text; } void - writeAlways(beast::severities::Severity level, std::string const& text) + writeAlways(beast::severities::Severity level, std::string&& text) override { logs_.logStream_ << text; @@ -217,13 +217,13 @@ public: } void - write(beast::severities::Severity level, std::string const& text) override + write(beast::severities::Severity level, std::string&& text) override { strm_ << text; } void - writeAlways(beast::severities::Severity level, std::string const& text) + writeAlways(beast::severities::Severity level, std::string&& text) override { strm_ << text;