]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw,mon,common/strtol: use strict_iec_cast(std::string_view, ..)
authorKefu Chai <kchai@redhat.com>
Mon, 26 Jul 2021 06:41:24 +0000 (14:41 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 26 Jul 2021 12:12:17 +0000 (20:12 +0800)
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 <kchai@redhat.com>
src/common/strtol.cc
src/common/strtol.h
src/mon/OSDMonitor.cc
src/rgw/rgw_admin.cc

index 11b900352968f47065217b9829234f08789e9e32..ad011b2097dcc2f50b8c6897388bd47767ac67b7 100644 (file)
@@ -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<uint64_t>(std::string_view(str), err);
-}
-
-template<typename T>
-T strict_iec_cast(const char *str, std::string *err)
-{
-  return strict_iec_cast<T>(std::string_view(str), err);
+  return strict_iec_cast<uint64_t>(str, err);
 }
 
-template int strict_iec_cast<int>(const char *str, std::string *err);
-template long strict_iec_cast<long>(const char *str, std::string *err);
-template long long strict_iec_cast<long long>(const char *str, std::string *err);
-template uint64_t strict_iec_cast<uint64_t>(const char *str, std::string *err);
-template uint32_t strict_iec_cast<uint32_t>(const char *str, std::string *err);
-
 template<typename T>
 T strict_si_cast(std::string_view str, std::string *err)
 {
index 1e243c33c3e851908c39550d2455441d6b7842ba..6af506a6ddcd14cb46f0e0247aa1dc6f027f36d8 100644 (file)
@@ -84,7 +84,7 @@ float strict_strtof(const char *str, std::string *err);
 uint64_t strict_iecstrtoll(const char *str, std::string *err);
 
 template<typename T>
-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);
 
index 92aca2887d68db370b3519e637fed702251bf4b7..c1fd12128c6af13fc42b1400015901710cbe3e9e 100644 (file)
@@ -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<int64_t>(val.c_str(), &interr);
   } else if (count(begin(iec_options), end(iec_options), var)) {
-    n = strict_iec_cast<int64_t>(val.c_str(), &interr);
+    n = strict_iec_cast<int64_t>(val, &interr);
   } else {
     // parse string as both int and float; different fields use different types.
     n = strict_strtoll(val.c_str(), 10, &interr);
index 3f0cae87907d30fafdc9446b7ede68e19c257d37..3a52b17bdf0f9c42c882e358707f6c099b905694 100644 (file)
@@ -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<long long>(val.c_str(), &err);
+      max_size = strict_iec_cast<long long>(val, &err);
       if (!err.empty()) {
         cerr << "ERROR: failed to parse max size: " << err << std::endl;
         return EINVAL;