Cast "const char *" to StringRef is now implicit and constexpr.

This commit is contained in:
Vitaly Baranov 2020-03-15 16:52:46 +03:00
parent 598b373b35
commit 5eb79c2303
4 changed files with 9 additions and 14 deletions

View File

@ -27,17 +27,17 @@ struct StringRef
size_t size = 0;
template <typename CharT, typename = std::enable_if_t<sizeof(CharT) == 1>>
StringRef(const CharT * data_, size_t size_) : data(reinterpret_cast<const char *>(data_)), size(size_) {}
constexpr StringRef(const CharT * data_, size_t size_) : data(reinterpret_cast<const char *>(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<StringRef>;

View File

@ -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);

View File

@ -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")

View File

@ -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);