]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mount/conf: avoid creating temporary object 46628/head
authorKefu Chai <tchaikov@gmail.com>
Sat, 11 Jun 2022 07:49:42 +0000 (15:49 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sat, 11 Jun 2022 07:49:42 +0000 (15:49 +0800)
instead of creating an empty string and then mutating it, just
assign the return value of `eaddr.ip_n_port_to_str()` to it.
as C++17 enforces copy ellision in this case, we can avoid
two unnecessary calls here:

- creating a temporary object and destroying it.
- memcpy the temporary object.

also, after this change, the code is simpler.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/mount/conf.cc

index 9a24aa53c3f1985472fdeccf8d70938cffeacd24..67fc9324e2f26e527c637af52b4df2518da2739b 100644 (file)
@@ -70,8 +70,7 @@ extern "C" void mount_ceph_get_config_info(const char *config_file,
        continue;
     }
 
-    std::string addr;
-    addr += eaddr.ip_n_port_to_str();
+    std::string addr = eaddr.ip_n_port_to_str();
     /* If this will overrun cci_mons, stop here */
     if (monaddrs.length() + 1 + addr.length() + 1 > sizeof(cci->cci_mons))
       break;