summaryrefslogtreecommitdiff
path: root/absl/log/internal/log_format.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/log/internal/log_format.cc')
-rw-r--r--absl/log/internal/log_format.cc33
1 files changed, 26 insertions, 7 deletions
diff --git a/absl/log/internal/log_format.cc b/absl/log/internal/log_format.cc
index 5d40d253..5b280a2d 100644
--- a/absl/log/internal/log_format.cc
+++ b/absl/log/internal/log_format.cc
@@ -46,6 +46,31 @@ ABSL_NAMESPACE_BEGIN
namespace log_internal {
namespace {
+// This templated function avoids compiler warnings about tautological
+// comparisons when log_internal::Tid is unsigned. It can be replaced with a
+// constexpr if once the minimum C++ version Abseil suppports is C++17.
+template <typename T>
+inline std::enable_if_t<!std::is_signed<T>::value>
+PutLeadingWhitespace(T tid, char*& p) {
+ if (tid < 10) *p++ = ' ';
+ if (tid < 100) *p++ = ' ';
+ if (tid < 1000) *p++ = ' ';
+ if (tid < 10000) *p++ = ' ';
+ if (tid < 100000) *p++ = ' ';
+ if (tid < 1000000) *p++ = ' ';
+}
+
+template <typename T>
+inline std::enable_if_t<std::is_signed<T>::value>
+PutLeadingWhitespace(T tid, char*& p) {
+ if (tid >= 0 && tid < 10) *p++ = ' ';
+ if (tid > -10 && tid < 100) *p++ = ' ';
+ if (tid > -100 && tid < 1000) *p++ = ' ';
+ if (tid > -1000 && tid < 10000) *p++ = ' ';
+ if (tid > -10000 && tid < 100000) *p++ = ' ';
+ if (tid > -100000 && tid < 1000000) *p++ = ' ';
+}
+
// The fields before the filename are all fixed-width except for the thread ID,
// which is of bounded width.
size_t FormatBoundedFields(absl::LogSeverity severity, absl::Time timestamp,
@@ -110,13 +135,7 @@ size_t FormatBoundedFields(absl::LogSeverity severity, absl::Time timestamp,
absl::numbers_internal::PutTwoDigits(static_cast<size_t>(usecs % 100), p);
p += 2;
*p++ = ' ';
- constexpr bool unsigned_tid_t = !std::is_signed<log_internal::Tid>::value;
- if ((unsigned_tid_t || tid >= 0) && tid < 10) *p++ = ' ';
- if ((unsigned_tid_t || tid > -10) && tid < 100) *p++ = ' ';
- if ((unsigned_tid_t || tid > -100) && tid < 1000) *p++ = ' ';
- if ((unsigned_tid_t || tid > -1000) && tid < 10000) *p++ = ' ';
- if ((unsigned_tid_t || tid > -10000) && tid < 100000) *p++ = ' ';
- if ((unsigned_tid_t || tid > -100000) && tid < 1000000) *p++ = ' ';
+ PutLeadingWhitespace(tid, p);
p = absl::numbers_internal::FastIntToBuffer(tid, p);
*p++ = ' ';
const size_t bytes_formatted = static_cast<size_t>(p - buf.data());