From: Kefu Chai Date: Sat, 11 Jun 2022 07:49:42 +0000 (+0800) Subject: mount/conf: avoid creating temporary object X-Git-Tag: v18.0.0~623^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=798e58bd39267d66b8d5964bcedf80fa1cd9e53c;p=ceph.git mount/conf: avoid creating temporary object 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 --- diff --git a/src/mount/conf.cc b/src/mount/conf.cc index 9a24aa53c3f..67fc9324e2f 100644 --- a/src/mount/conf.cc +++ b/src/mount/conf.cc @@ -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;