Minor ConfigShared improvements.

This commit is contained in:
levlam 2022-05-14 19:59:11 +03:00
parent c17520fdbc
commit 514ffd7e77

View File

@ -39,13 +39,13 @@ void ConfigShared::set_option_empty(Slice name) {
} }
void ConfigShared::set_option_integer(Slice name, int64 value) { void ConfigShared::set_option_integer(Slice name, int64 value) {
if (set_option(name, PSLICE() << "I" << value)) { if (set_option(name, PSLICE() << 'I' << value)) {
on_option_updated(name); on_option_updated(name);
} }
} }
void ConfigShared::set_option_string(Slice name, Slice value) { void ConfigShared::set_option_string(Slice name, Slice value) {
if (set_option(name, PSLICE() << "S" << value)) { if (set_option(name, PSLICE() << 'S' << value)) {
on_option_updated(name); on_option_updated(name);
} }
} }
@ -73,32 +73,32 @@ bool ConfigShared::get_option_boolean(Slice name, bool default_value) const {
if (value == "Bfalse") { if (value == "Bfalse") {
return false; return false;
} }
LOG(ERROR) << "Found \"" << value << "\" instead of boolean option"; LOG(ERROR) << "Found \"" << value << "\" instead of boolean option " << name;
return default_value; return default_value;
} }
int64 ConfigShared::get_option_integer(Slice name, int64 default_value) const { int64 ConfigShared::get_option_integer(Slice name, int64 default_value) const {
auto str_value = get_option(name); auto value = get_option(name);
if (str_value.empty()) { if (value.empty()) {
return default_value; return default_value;
} }
if (str_value[0] != 'I') { if (value[0] != 'I') {
LOG(ERROR) << "Found \"" << str_value << "\" instead of integer option"; LOG(ERROR) << "Found \"" << value << "\" instead of integer option " << name;
return default_value; return default_value;
} }
return to_integer<int64>(str_value.substr(1)); return to_integer<int64>(value.substr(1));
} }
string ConfigShared::get_option_string(Slice name, string default_value) const { string ConfigShared::get_option_string(Slice name, string default_value) const {
auto str_value = get_option(name); auto value = get_option(name);
if (str_value.empty()) { if (value.empty()) {
return default_value; return default_value;
} }
if (str_value[0] != 'S') { if (value[0] != 'S') {
LOG(ERROR) << "Found \"" << str_value << "\" instead of string option"; LOG(ERROR) << "Found \"" << value << "\" instead of string option " << name;
return default_value; return default_value;
} }
return str_value.substr(1); return value.substr(1);
} }
bool ConfigShared::set_option(Slice name, Slice value) { bool ConfigShared::set_option(Slice name, Slice value) {