Skip to content

Commit 8ef94d2

Browse files
committed
Avoid passing some function arguments by value
Preemptively avoid clang-tidy errors before clang-tidy is introduced in #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<Thread::Server&> 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)); ^~~~~~~~~~ ~
1 parent 1af83d1 commit 8ef94d2

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

example/calculator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class InitImpl : public Init
3030
}
3131
};
3232

33-
void LogPrint(bool raise, std::string message)
33+
void LogPrint(bool raise, const std::string& message)
3434
{
35-
if (raise) throw std::runtime_error(std::move(message));
35+
if (raise) throw std::runtime_error(message);
3636
std::ofstream("debug.log", std::ios_base::app) << message << std::endl;
3737
}
3838

example/example.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ auto Spawn(mp::EventLoop& loop, const std::string& process_argv0, const std::str
2323
return std::make_tuple(mp::ConnectStream<InitInterface>(loop, fd), pid);
2424
}
2525

26-
void LogPrint(bool raise, std::string message)
26+
void LogPrint(bool raise, const std::string& message)
2727
{
28-
if (raise) throw std::runtime_error(std::move(message));
28+
if (raise) throw std::runtime_error(message);
2929
std::ofstream("debug.log", std::ios_base::app) << message << std::endl;
3030
}
3131

example/printer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class InitImpl : public Init
2424
std::unique_ptr<Printer> makePrinter() override { return std::make_unique<PrinterImpl>(); }
2525
};
2626

27-
void LogPrint(bool raise, std::string message)
27+
void LogPrint(bool raise, const std::string& message)
2828
{
29-
if (raise) throw std::runtime_error(std::move(message));
29+
if (raise) throw std::runtime_error(message);
3030
std::ofstream("debug.log", std::ios_base::app) << message << std::endl;
3131
}
3232

include/mp/proxy-types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
159159

160160
auto thread_client = context_arg.getThread();
161161
return JoinPromises(server.m_context.connection->m_threads.getLocalServer(thread_client)
162-
.then([&server, invoke, req](kj::Maybe<Thread::Server&> perhaps) {
162+
.then([&server, invoke, req](const kj::Maybe<Thread::Server&>& perhaps) {
163163
KJ_IF_MAYBE(thread_server, perhaps)
164164
{
165165
const auto& thread = static_cast<ProxyServer<Thread>&>(*thread_server);

0 commit comments

Comments
 (0)