From 1ffb3747bd30d3d7bad9cfedf056aea6b243a687 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Fri, 4 May 2018 15:04:48 +0200 Subject: [PATCH] RTC_LOG(): Internally, pass logging severity as template argument When the logging severity is statically known, passing it as a template argument instead of as a function argument saves space at the call site. Because this is a constructor, it's not possible to pass template arguments explicitly---they need to be deduced. So we pass a dummy function argument whose type encodes the logging severity, and because the dummy is an empty struct, the ABI generally specifies that this is a no-op with no runtime cost. In aggregate, this reduces the size of libjingle_peerconnection_so.so by 4 kB. Bug: webrtc:9185 Change-Id: I8118f39dc2aed3be34b2979a239fc0d3dffa969f Reviewed-on: https://webrtc-review.googlesource.com/74582 Commit-Queue: Karl Wiberg Reviewed-by: Fredrik Solenberg Cr-Commit-Position: refs/heads/master@{#23136} --- rtc_base/logging.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/rtc_base/logging.h b/rtc_base/logging.h index 6ff31f3fda..e25d56e935 100644 --- a/rtc_base/logging.h +++ b/rtc_base/logging.h @@ -123,6 +123,16 @@ class LogSink { class LogMessage { public: LogMessage(const char* file, int line, LoggingSeverity sev); + + // Same as the above, but using a compile-time constant for the logging + // severity. This saves space at the call site, since passing an empty struct + // is generally the same as not passing an argument at all. + template + RTC_NO_INLINE LogMessage(const char* file, + int line, + std::integral_constant) + : LogMessage(file, line, S) {} + LogMessage(const char* file, int line, LoggingSeverity sev, @@ -281,9 +291,11 @@ class LogMessageVoidify { #define RTC_LOG_SEVERITY_PRECONDITION_C(sev) \ !(rtc::LogMessage::Loggable()) ? (void)0 : rtc::LogMessageVoidify()& -#define RTC_LOG(sev) \ - RTC_LOG_SEVERITY_PRECONDITION_C(sev) \ - rtc::LogMessage(__FILE__, __LINE__, rtc::sev).stream() +#define RTC_LOG(sev) \ + RTC_LOG_SEVERITY_PRECONDITION_C(sev) \ + rtc::LogMessage(__FILE__, __LINE__, \ + std::integral_constant()) \ + .stream() // The _V version is for when a variable is passed in. It doesn't do the // namespace concatenation.