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. In aggregate, this reduces the size of libjingle_peerconnection_so.so by 8 kB. Bug: webrtc:9185 Change-Id: I9ca363845216370e97b230952c86e6d07719962f Reviewed-on: https://webrtc-review.googlesource.com/74480 Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org> Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org> Commit-Queue: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23121}
This commit is contained in:
@ -218,6 +218,7 @@ rtc_source_set("logging") {
|
||||
"logging.cc",
|
||||
"logging.h",
|
||||
]
|
||||
deps += [ "system:no_inline" ]
|
||||
|
||||
# logging.h needs the deprecation header while downstream projects are
|
||||
# removing code that depends on logging implementation details.
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "rtc_base/basictypes.h"
|
||||
#include "rtc_base/constructormagic.h"
|
||||
#include "rtc_base/deprecation.h"
|
||||
#include "rtc_base/system/no_inline.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
|
||||
#if !defined(NDEBUG) || defined(DLOG_ALWAYS_ON)
|
||||
@ -142,6 +143,16 @@ class LogMessage {
|
||||
~LogMessage();
|
||||
|
||||
static bool Loggable(LoggingSeverity sev);
|
||||
|
||||
// Same as the above, but using a template argument instead of a function
|
||||
// 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.)
|
||||
template <LoggingSeverity S>
|
||||
RTC_NO_INLINE static bool Loggable() {
|
||||
return Loggable(S);
|
||||
}
|
||||
|
||||
std::ostream& stream();
|
||||
|
||||
// Returns the time at which this function was called for the first time.
|
||||
@ -268,9 +279,11 @@ class LogMessageVoidify {
|
||||
? (void) 0 \
|
||||
: rtc::LogMessageVoidify() &
|
||||
|
||||
#define RTC_LOG(sev) \
|
||||
RTC_LOG_SEVERITY_PRECONDITION(rtc::sev) \
|
||||
rtc::LogMessage(__FILE__, __LINE__, rtc::sev).stream()
|
||||
#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()
|
||||
|
||||
// The _V version is for when a variable is passed in. It doesn't do the
|
||||
// namespace concatenation.
|
||||
@ -297,11 +310,11 @@ inline bool LogCheckLevel(LoggingSeverity sev) {
|
||||
return (LogMessage::GetMinLogSeverity() <= sev);
|
||||
}
|
||||
|
||||
#define RTC_LOG_E(sev, ctx, err, ...) \
|
||||
RTC_LOG_SEVERITY_PRECONDITION(rtc::sev) \
|
||||
rtc::LogMessage(__FILE__, __LINE__, rtc::sev, \
|
||||
rtc::ERRCTX_ ## ctx, err , ##__VA_ARGS__) \
|
||||
.stream()
|
||||
#define RTC_LOG_E(sev, ctx, err, ...) \
|
||||
RTC_LOG_SEVERITY_PRECONDITION_C(sev) \
|
||||
rtc::LogMessage(__FILE__, __LINE__, rtc::sev, rtc::ERRCTX_##ctx, err, \
|
||||
##__VA_ARGS__) \
|
||||
.stream()
|
||||
|
||||
#define RTC_LOG_T(sev) RTC_LOG(sev) << this << ": "
|
||||
|
||||
|
@ -42,3 +42,9 @@ rtc_source_set("ignore_warnings") {
|
||||
"ignore_warnings.h",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_source_set("no_inline") {
|
||||
sources = [
|
||||
"no_inline.h",
|
||||
]
|
||||
}
|
||||
|
22
rtc_base/system/no_inline.h
Normal file
22
rtc_base/system/no_inline.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef RTC_BASE_SYSTEM_NO_INLINE_H_
|
||||
#define RTC_BASE_SYSTEM_NO_INLINE_H_
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define RTC_NO_INLINE __declspec(noinline)
|
||||
#elif defined(__GNUC__)
|
||||
#define RTC_NO_INLINE __attribute__((__noinline__))
|
||||
#else
|
||||
#define RTC_NO_INLINE
|
||||
#endif
|
||||
|
||||
#endif // RTC_BASE_SYSTEM_NO_INLINE_H_
|
Reference in New Issue
Block a user