From 5eb79c2303d162a44c64b5b35148d19a63959418 Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Sun, 15 Mar 2020 16:52:46 +0300 Subject: [PATCH] Cast "const char *" to StringRef is now implicit and constexpr. --- base/common/StringRef.h | 10 +++++----- dbms/src/IO/WriteHelpers.h | 5 ----- dbms/src/Interpreters/Context.cpp | 4 ++-- dbms/src/Interpreters/Context.h | 4 ++-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/base/common/StringRef.h b/base/common/StringRef.h index 961aab58980..076b8982b1d 100644 --- a/base/common/StringRef.h +++ b/base/common/StringRef.h @@ -27,17 +27,17 @@ struct StringRef size_t size = 0; template > - StringRef(const CharT * data_, size_t size_) : data(reinterpret_cast(data_)), size(size_) {} + constexpr StringRef(const CharT * data_, size_t size_) : data(reinterpret_cast(data_)), size(size_) {} StringRef(const std::string & s) : data(s.data()), size(s.size()) {} - StringRef(const std::string_view & s) : data(s.data()), size(s.size()) {} - explicit StringRef(const char * data_) : data(data_), size(strlen(data_)) {} - StringRef() = default; + constexpr StringRef(const std::string_view & s) : data(s.data()), size(s.size()) {} + constexpr StringRef(const char * data_) : StringRef(std::string_view{data_}) {} + constexpr StringRef() = default; std::string toString() const { return std::string(data, size); } explicit operator std::string() const { return toString(); } - explicit operator std::string_view() const { return {data, size}; } + constexpr explicit operator std::string_view() const { return {data, size}; } }; using StringRefs = std::vector; diff --git a/dbms/src/IO/WriteHelpers.h b/dbms/src/IO/WriteHelpers.h index 44b0322ee83..10918fb7b61 100644 --- a/dbms/src/IO/WriteHelpers.h +++ b/dbms/src/IO/WriteHelpers.h @@ -239,11 +239,6 @@ inline void writeFloatText(T x, WriteBuffer & buf) } -inline void writeString(const String & s, WriteBuffer & buf) -{ - buf.write(s.data(), s.size()); -} - inline void writeString(const char * data, size_t size, WriteBuffer & buf) { buf.write(data, size); diff --git a/dbms/src/Interpreters/Context.cpp b/dbms/src/Interpreters/Context.cpp index ab9b4a2c31b..ef45fd60e81 100644 --- a/dbms/src/Interpreters/Context.cpp +++ b/dbms/src/Interpreters/Context.cpp @@ -947,7 +947,7 @@ void Context::setSettings(const Settings & settings_) } -void Context::setSetting(const String & name, const String & value) +void Context::setSetting(const StringRef & name, const String & value) { auto lock = getLock(); if (name == "profile") @@ -962,7 +962,7 @@ void Context::setSetting(const String & name, const String & value) } -void Context::setSetting(const String & name, const Field & value) +void Context::setSetting(const StringRef & name, const Field & value) { auto lock = getLock(); if (name == "profile") diff --git a/dbms/src/Interpreters/Context.h b/dbms/src/Interpreters/Context.h index 5d8351ed598..2f049d14cd3 100644 --- a/dbms/src/Interpreters/Context.h +++ b/dbms/src/Interpreters/Context.h @@ -344,8 +344,8 @@ public: void setSettings(const Settings & settings_); /// Set settings by name. - void setSetting(const String & name, const String & value); - void setSetting(const String & name, const Field & value); + void setSetting(const StringRef & name, const String & value); + void setSetting(const StringRef & name, const Field & value); void applySettingChange(const SettingChange & change); void applySettingsChanges(const SettingsChanges & changes);