From: Davin McCall Date: Fri, 13 Dec 2019 10:05:47 +0000 (+1000) Subject: Avoid copying string arguments to log functions (always pass by ref) X-Git-Tag: v0.8.1~24 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f661bb3eca6aa9b7d651b2c3ceb0568799c9201f;p=oweals%2Fdinit.git Avoid copying string arguments to log functions (always pass by ref) --- diff --git a/src/dinit-log.cc b/src/dinit-log.cc index fd15e22..990ffef 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -424,7 +424,7 @@ void log(loglevel_t lvl, bool to_cons, const char *msg) noexcept } // Log part of a message. A series of calls to do_log_part must be followed by a call to do_log_commit. -template static void do_log_part(int idx, T arg) noexcept +static void do_log_part(int idx, const char *arg) noexcept { if (log_current_line[idx]) { int amount = sum_length(arg); diff --git a/src/includes/dinit-log.h b/src/includes/dinit-log.h index ccff5e7..534a0b7 100644 --- a/src/includes/dinit-log.h +++ b/src/includes/dinit-log.h @@ -118,12 +118,12 @@ static inline void log_service_stopped(const std::string &str) noexcept // It's not intended that methods in this namespace be called directly: namespace dinit_log { - template static inline void log_parts(A a) noexcept + template static inline void log_parts(const A &a) noexcept { log_msg_end(a); } - template static inline void log_parts(A a, B... b) noexcept + template static inline void log_parts(const A &a, const B & ...b) noexcept { log_msg_part(a); log_parts(b...); @@ -131,13 +131,7 @@ namespace dinit_log { } // Variadic 'log' method. -template static inline void log(loglevel_t lvl, bool log_cons, A a, B ...b) noexcept -{ - log_msg_begin(lvl, a); - dinit_log::log_parts(b...); -} - -template static inline void log(loglevel_t lvl, A a, B ...b) noexcept +template static inline void log(loglevel_t lvl, const A &a, const B & ...b) noexcept { log_msg_begin(lvl, a); dinit_log::log_parts(b...);