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 <kwiberg@webrtc.org> Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23136}
This commit is contained in:
parent
a4e37a8f82
commit
1ffb3747bd
@ -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 <LoggingSeverity S>
|
||||
RTC_NO_INLINE LogMessage(const char* file,
|
||||
int line,
|
||||
std::integral_constant<LoggingSeverity, S>)
|
||||
: 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<rtc::sev>()) ? (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<rtc::LoggingSeverity, rtc::sev>()) \
|
||||
.stream()
|
||||
|
||||
// The _V version is for when a variable is passed in. It doesn't do the
|
||||
// namespace concatenation.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user