From: Kefu Chai Date: Mon, 26 Jul 2021 06:41:24 +0000 (+0800) Subject: rgw,mon,common/strtol: use strict_iec_cast(std::string_view, ..) X-Git-Tag: v17.1.0~1287^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=58c4ece8f35b090c7957d52bd7c84f6783d86f90;p=ceph.git rgw,mon,common/strtol: use strict_iec_cast(std::string_view, ..) this variant is better than strict_iec_cast(const char*), because: * we can just pass std::string to it, as std::string_view can be constructed from a std::string implicitly * strict_iec_cast(std::string_view, ..) is the underlying implementation of strict_iec_cast(const char*,..), so less indirection helps with the readability. * rgw,mon: use strict_iec_cast(std::string_view, ..) instead. Signed-off-by: Kefu Chai --- diff --git a/src/common/strtol.cc b/src/common/strtol.cc index 11b900352968..ad011b2097dc 100644 --- a/src/common/strtol.cc +++ b/src/common/strtol.cc @@ -237,21 +237,9 @@ uint64_t strict_iecstrtoll(std::string_view str, std::string *err) uint64_t strict_iecstrtoll(const char *str, std::string *err) { - return strict_iec_cast(std::string_view(str), err); -} - -template -T strict_iec_cast(const char *str, std::string *err) -{ - return strict_iec_cast(std::string_view(str), err); + return strict_iec_cast(str, err); } -template int strict_iec_cast(const char *str, std::string *err); -template long strict_iec_cast(const char *str, std::string *err); -template long long strict_iec_cast(const char *str, std::string *err); -template uint64_t strict_iec_cast(const char *str, std::string *err); -template uint32_t strict_iec_cast(const char *str, std::string *err); - template T strict_si_cast(std::string_view str, std::string *err) { diff --git a/src/common/strtol.h b/src/common/strtol.h index 1e243c33c3e8..6af506a6ddcd 100644 --- a/src/common/strtol.h +++ b/src/common/strtol.h @@ -84,7 +84,7 @@ float strict_strtof(const char *str, std::string *err); uint64_t strict_iecstrtoll(const char *str, std::string *err); template -T strict_iec_cast(const char *str, std::string *err); +T strict_iec_cast(std::string_view str, std::string *err); uint64_t strict_sistrtoll(const char *str, std::string *err); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 92aca2887d68..c1fd12128c6a 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -8130,7 +8130,7 @@ int OSDMonitor::prepare_command_pool_set(const cmdmap_t& cmdmap, if (count(begin(si_options), end(si_options), var)) { n = strict_si_cast(val.c_str(), &interr); } else if (count(begin(iec_options), end(iec_options), var)) { - n = strict_iec_cast(val.c_str(), &interr); + n = strict_iec_cast(val, &interr); } else { // parse string as both int and float; different fields use different types. n = strict_strtoll(val.c_str(), 10, &interr); diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 3f0cae87907d..3a52b17bdf0f 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -3322,7 +3322,7 @@ int main(int argc, const char **argv) return EINVAL; } } else if (ceph_argparse_witharg(args, i, &val, "--max-size", (char*)NULL)) { - max_size = strict_iec_cast(val.c_str(), &err); + max_size = strict_iec_cast(val, &err); if (!err.empty()) { cerr << "ERROR: failed to parse max size: " << err << std::endl; return EINVAL;