From 8ef94d2e866bc153a231f94e0fbe20786357904e Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Tue, 14 Feb 2023 16:17:44 -0500 Subject: [PATCH] Avoid passing some function arguments by value Preemptively avoid clang-tidy errors before clang-tidy is introduced in https://github.com/chaincodelabs/libmultiprocess/pull/83. Other clang errors are already fixed in that PR, these aren't (maybe due to running different clang-tidy versions). The errors look like: include/mp/proxy-types.h:162:85: warning: the parameter 'perhaps' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] .then([&server, invoke, req](kj::Maybe perhaps) { ^ const & example/printer.cpp:27:39: warning: the parameter 'message' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] void LogPrint(bool raise, std::string message) ^ example/printer.cpp:29:41: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] if (raise) throw std::runtime_error(std::move(message)); ^~~~~~~~~~ ~ --- example/calculator.cpp | 4 ++-- example/example.cpp | 4 ++-- example/printer.cpp | 4 ++-- include/mp/proxy-types.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example/calculator.cpp b/example/calculator.cpp index 956a5d60..65f6476e 100644 --- a/example/calculator.cpp +++ b/example/calculator.cpp @@ -30,9 +30,9 @@ class InitImpl : public Init } }; -void LogPrint(bool raise, std::string message) +void LogPrint(bool raise, const std::string& message) { - if (raise) throw std::runtime_error(std::move(message)); + if (raise) throw std::runtime_error(message); std::ofstream("debug.log", std::ios_base::app) << message << std::endl; } diff --git a/example/example.cpp b/example/example.cpp index 3c8a7479..ecaabafb 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -23,9 +23,9 @@ auto Spawn(mp::EventLoop& loop, const std::string& process_argv0, const std::str return std::make_tuple(mp::ConnectStream(loop, fd), pid); } -void LogPrint(bool raise, std::string message) +void LogPrint(bool raise, const std::string& message) { - if (raise) throw std::runtime_error(std::move(message)); + if (raise) throw std::runtime_error(message); std::ofstream("debug.log", std::ios_base::app) << message << std::endl; } diff --git a/example/printer.cpp b/example/printer.cpp index f24f60c2..0a51cdd4 100644 --- a/example/printer.cpp +++ b/example/printer.cpp @@ -24,9 +24,9 @@ class InitImpl : public Init std::unique_ptr makePrinter() override { return std::make_unique(); } }; -void LogPrint(bool raise, std::string message) +void LogPrint(bool raise, const std::string& message) { - if (raise) throw std::runtime_error(std::move(message)); + if (raise) throw std::runtime_error(message); std::ofstream("debug.log", std::ios_base::app) << message << std::endl; } diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index 4679f8d2..902bd240 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -159,7 +159,7 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn& auto thread_client = context_arg.getThread(); return JoinPromises(server.m_context.connection->m_threads.getLocalServer(thread_client) - .then([&server, invoke, req](kj::Maybe perhaps) { + .then([&server, invoke, req](const kj::Maybe& perhaps) { KJ_IF_MAYBE(thread_server, perhaps) { const auto& thread = static_cast&>(*thread_server);