summaryrefslogtreecommitdiff
path: root/absl/log
diff options
context:
space:
mode:
authorGravatar Andy Getzendanner <durandal@google.com>2023-04-28 14:37:49 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-04-28 14:38:29 -0700
commite9a7eea615352e2f74c13585a4b031f868b3bfa7 (patch)
tree8a3ac4ca7d40ffb5c7282dc55e4ffa3448842817 /absl/log
parent56c5fc620161e12844b9b92d06f8954b29f40bf4 (diff)
Shrink most LOG callsites by one instruction (SysV x86_64 ABI) by dispatching to per-severity constructors and omitting the severity argument.
In that particular ABI, the empty tag structs are NO_CLASS and don't appear in the generated code. https://godbolt.org/z/crqaPh8Kv PiperOrigin-RevId: 527989179 Change-Id: I365f11f6ca1de2623690d0a04e6f02f7de82b1fc
Diffstat (limited to 'absl/log')
-rw-r--r--absl/log/internal/log_message.cc12
-rw-r--r--absl/log/internal/log_message.h12
-rw-r--r--absl/log/internal/strip.h18
3 files changed, 30 insertions, 12 deletions
diff --git a/absl/log/internal/log_message.cc b/absl/log/internal/log_message.cc
index bdb10f2a..4deca722 100644
--- a/absl/log/internal/log_message.cc
+++ b/absl/log/internal/log_message.cc
@@ -234,6 +234,13 @@ LogMessage::LogMessage(const char* file, int line, absl::LogSeverity severity)
LogBacktraceIfNeeded();
}
+LogMessage::LogMessage(const char* file, int line, InfoTag)
+ : LogMessage(file, line, absl::LogSeverity::kInfo) {}
+LogMessage::LogMessage(const char* file, int line, WarningTag)
+ : LogMessage(file, line, absl::LogSeverity::kWarning) {}
+LogMessage::LogMessage(const char* file, int line, ErrorTag)
+ : LogMessage(file, line, absl::LogSeverity::kError) {}
+
LogMessage::~LogMessage() {
#ifdef ABSL_MIN_LOG_LEVEL
if (data_->entry.log_severity() <
@@ -383,8 +390,7 @@ template LogMessage& LogMessage::operator<<(const double& v);
template LogMessage& LogMessage::operator<<(const bool& v);
void LogMessage::Flush() {
- if (data_->entry.log_severity() < absl::MinLogLevel())
- return;
+ if (data_->entry.log_severity() < absl::MinLogLevel()) return;
if (data_->is_perror) {
InternalStream() << ": " << absl::base_internal::StrError(errno_saver_())
@@ -427,7 +433,7 @@ LogMessage::OstreamView::OstreamView(LogMessageData& message_data)
&encoded_remaining_copy_);
string_start_ =
EncodeMessageStart(ValueTag::kString, encoded_remaining_copy_.size(),
- &encoded_remaining_copy_);
+ &encoded_remaining_copy_);
setp(encoded_remaining_copy_.data(),
encoded_remaining_copy_.data() + encoded_remaining_copy_.size());
data_.manipulated.rdbuf(this);
diff --git a/absl/log/internal/log_message.h b/absl/log/internal/log_message.h
index 3744276b..6fdfa7bd 100644
--- a/absl/log/internal/log_message.h
+++ b/absl/log/internal/log_message.h
@@ -51,9 +51,21 @@ constexpr int kLogMessageBufferSize = 15000;
class LogMessage {
public:
+ struct InfoTag {};
+ struct WarningTag {};
+ struct ErrorTag {};
+
// Used for `LOG`.
LogMessage(const char* file, int line,
absl::LogSeverity severity) ABSL_ATTRIBUTE_COLD;
+ // These constructors are slightly smaller/faster to call; the severity is
+ // curried into the function pointer.
+ LogMessage(const char* file, int line,
+ InfoTag) ABSL_ATTRIBUTE_COLD ABSL_ATTRIBUTE_NOINLINE;
+ LogMessage(const char* file, int line,
+ WarningTag) ABSL_ATTRIBUTE_COLD ABSL_ATTRIBUTE_NOINLINE;
+ LogMessage(const char* file, int line,
+ ErrorTag) ABSL_ATTRIBUTE_COLD ABSL_ATTRIBUTE_NOINLINE;
LogMessage(const LogMessage&) = delete;
LogMessage& operator=(const LogMessage&) = delete;
~LogMessage() ABSL_ATTRIBUTE_COLD;
diff --git a/absl/log/internal/strip.h b/absl/log/internal/strip.h
index 848c3867..adc86ffd 100644
--- a/absl/log/internal/strip.h
+++ b/absl/log/internal/strip.h
@@ -42,15 +42,15 @@
#define ABSL_LOG_INTERNAL_QCHECK(failure_message) \
ABSL_LOGGING_INTERNAL_LOG_QFATAL
#else // !defined(STRIP_LOG) || !STRIP_LOG
-#define ABSL_LOGGING_INTERNAL_LOG_INFO \
- ::absl::log_internal::LogMessage(__FILE__, __LINE__, \
- ::absl::LogSeverity::kInfo)
-#define ABSL_LOGGING_INTERNAL_LOG_WARNING \
- ::absl::log_internal::LogMessage(__FILE__, __LINE__, \
- ::absl::LogSeverity::kWarning)
-#define ABSL_LOGGING_INTERNAL_LOG_ERROR \
- ::absl::log_internal::LogMessage(__FILE__, __LINE__, \
- ::absl::LogSeverity::kError)
+#define ABSL_LOGGING_INTERNAL_LOG_INFO \
+ ::absl::log_internal::LogMessage( \
+ __FILE__, __LINE__, ::absl::log_internal::LogMessage::InfoTag{})
+#define ABSL_LOGGING_INTERNAL_LOG_WARNING \
+ ::absl::log_internal::LogMessage( \
+ __FILE__, __LINE__, ::absl::log_internal::LogMessage::WarningTag{})
+#define ABSL_LOGGING_INTERNAL_LOG_ERROR \
+ ::absl::log_internal::LogMessage( \
+ __FILE__, __LINE__, ::absl::log_internal::LogMessage::ErrorTag{})
#define ABSL_LOGGING_INTERNAL_LOG_FATAL \
::absl::log_internal::LogMessageFatal(__FILE__, __LINE__)
#define ABSL_LOGGING_INTERNAL_LOG_QFATAL \