Skip to content

Commit

Permalink
mount/conf: avoid creating temporary object
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tchaikov committed Jun 11, 2022
1 parent 01f9dc8 commit 798e58b
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/mount/conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 798e58b

Please sign in to comment.