]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/config: use libfmt to build strings
authorMax Kellermann <max.kellermann@ionos.com>
Fri, 4 Oct 2024 12:26:43 +0000 (14:26 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Wed, 9 Oct 2024 20:45:18 +0000 (22:45 +0200)
The machine code is both smaller and faster.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/common/config.cc

index 9083c3a66ba9b06931c6e61be443e178bdcfe73b..3a5ee91c3472c76316de6e6e0f62e68072e75d0a 100644 (file)
@@ -24,6 +24,8 @@
 #include "common/hostname.h"
 #include "common/dout.h"
 
+#include <fmt/core.h>
+
 /* Don't use standard Ceph logging in this file.
  * We can't use logging until it's initialized, and a lot of the necessary
  * initialization happens here.
@@ -131,14 +133,11 @@ md_config_t::md_config_t(ConfigValues& values,
   // Define the debug_* options as well.
   subsys_options.reserve(values.subsys.get_num());
   for (unsigned i = 0; i < values.subsys.get_num(); ++i) {
-    string name = string("debug_") + values.subsys.get_name(i);
     subsys_options.emplace_back(
-      name, Option::TYPE_STR, Option::LEVEL_ADVANCED);
+      fmt::format("debug_{}", values.subsys.get_name(i)), Option::TYPE_STR, Option::LEVEL_ADVANCED);
     Option& opt = subsys_options.back();
-    opt.set_default(stringify(values.subsys.get_log_level(i)) + "/" +
-                   stringify(values.subsys.get_gather_level(i)));
-    string desc = string("Debug level for ") + values.subsys.get_name(i);
-    opt.set_description(desc.c_str());
+    opt.set_default(fmt::format("{}/{}", values.subsys.get_log_level(i), values.subsys.get_gather_level(i)));
+    opt.set_description(fmt::format("Debug level for {}", values.subsys.get_name(i)).c_str());
     opt.set_flag(Option::FLAG_RUNTIME);
     opt.set_long_description("The value takes the form 'N' or 'N/M' where N and M are values between 0 and 99.  N is the debug level to log (all values below this are included), and M is the level to gather and buffer in memory.  In the event of a crash, the most recent items <= M are dumped to the log file.");
     opt.set_subsys(i);
@@ -158,7 +157,7 @@ md_config_t::md_config_t(ConfigValues& values,
          } else {
            // normalize to M/N
            n = m;
-           *value = stringify(m) + "/" + stringify(n);
+           *value = fmt::format("{}/{}", m, n);
          }
        } else {
          *error_message = "value must take the form N or N/M, where N and M are integers";
@@ -775,7 +774,7 @@ int md_config_t::parse_option(ConfigValues& values,
     option_name = opt.name;
     if (ceph_argparse_witharg(
          args, i, &val, err,
-         string(string("--default-") + opt.name).c_str(), (char*)NULL)) {
+         fmt::format("--default-{}", opt.name).c_str(), (char*)NULL)) {
       if (!err.str().empty()) {
         error_message = err.str();
        ret = -EINVAL;
@@ -1268,7 +1267,7 @@ Option::value_t md_config_t::_expand_meta(
                     << Option::to_str(*i->second) << "\n";
              }
            }
-           return Option::value_t(std::string("$") + o->name);
+           return Option::value_t(fmt::format("${}", o->name));
          } else {
            // recursively evaluate!
            string n;