Optimize logging of const strings.

GitOrigin-RevId: af8de902d07c4862a77e0d8050db47ee1ccacbf6
This commit is contained in:
levlam 2020-08-20 22:28:00 +03:00
parent 3fdf575fb3
commit 2c4953386a

View File

@ -39,9 +39,22 @@ class StringBuilder {
return error_flag_;
}
StringBuilder &operator<<(const char *str) {
template <class T>
std::enable_if_t<std::is_same<char *, std::remove_const_t<T>>::value, StringBuilder> &operator<<(T str) {
return *this << Slice(str);
}
template <class T>
std::enable_if_t<std::is_same<const char *, std::remove_const_t<T>>::value, StringBuilder> &operator<<(T str) {
return *this << Slice(str);
}
template <size_t N>
StringBuilder &operator<<(char (&str)[N]) = delete;
template <size_t N>
StringBuilder &operator<<(const char (&str)[N]) {
return *this << Slice(str, N - 1);
}
StringBuilder &operator<<(const wchar_t *str) = delete;
@ -94,11 +107,6 @@ class StringBuilder {
StringBuilder &operator<<(const void *ptr);
template <class T>
StringBuilder &operator<<(const T *ptr) {
return *this << static_cast<const void *>(ptr);
}
private:
char *begin_ptr_;
char *current_ptr_;