Delete rtc::LeftPad

Single use replaced with snprintf (old code also uses snprintf, but
twice, via rtc::ToString).

Bug: webrtc:6424
Change-Id: Iedb30aacb351428974067141e166cbc53fdda180
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/184365
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32127}
This commit is contained in:
Niels Möller 2020-09-17 12:40:02 +02:00 committed by Commit Bot
parent aef8a21a69
commit 646109f379
3 changed files with 8 additions and 11 deletions

View File

@ -33,6 +33,7 @@
static const int kMaxLogLineSize = 1024 - 60;
#endif // WEBRTC_MAC && !defined(WEBRTC_IOS) || WEBRTC_ANDROID
#include <inttypes.h>
#include <stdio.h>
#include <time.h>
@ -110,9 +111,13 @@ LogMessage::LogMessage(const char* file,
// Also ensure WallClockStartTime is initialized, so that it matches
// LogStartTime.
WallClockStartTime();
print_stream_ << "[" << rtc::LeftPad('0', 3, rtc::ToString(time / 1000))
<< ":" << rtc::LeftPad('0', 3, rtc::ToString(time % 1000))
<< "] ";
// TODO(kwiberg): Switch to absl::StrFormat, if binary size is ok.
char timestamp[50]; // Maximum string length of an int64_t is 20.
int len =
snprintf(timestamp, sizeof(timestamp), "[%03" PRId64 ":%03" PRId64 "]",
time / 1000, time % 1000);
RTC_DCHECK_LT(len, sizeof(timestamp));
print_stream_ << timestamp;
}
if (thread_) {

View File

@ -50,10 +50,4 @@ std::string ToHex(const int i) {
return std::string(buffer);
}
std::string LeftPad(char padding, unsigned length, std::string s) {
if (s.length() >= length)
return s;
return std::string(length - s.length(), padding) + s;
}
} // namespace rtc

View File

@ -88,8 +88,6 @@ std::string string_trim(const std::string& s);
// TODO(jonasolsson): replace with absl::Hex when that becomes available.
std::string ToHex(const int i);
std::string LeftPad(char padding, unsigned length, std::string s);
} // namespace rtc
#endif // RTC_BASE_STRING_UTILS_H_