-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inet_address: Remove to_sstring() in favor of fmt::to_string #18712
Conversation
Your patch is lacking motivation: In classic OO programming, a method is better than a global function. Among other things, when you have a method on a method Another result of your change is that we convert the address into an An example of the std::string vs. seastar::sstring issue is the following code (after your patch): std::map<sstring, sstring> nodes_status;
g.for_each_endpoint_state([&] (const gms::inet_address& node, const gms::endpoint_state&) {
nodes_status.emplace(fmt::to_string(node), g.is_alive(node) ? "UP" : "DOWN"); Note how you build a map of seastar::sstring, yet you put into it a std::string returned by fmt::to_string(). This requires unnecessary conversions between the two. In this case you should probably make the map have a std::string key instead of sstring. It's not a bad idea (in Alternator I also moved away from sstring to std::string as much as possible), but I think it needs to be done more carefully. |
The existing inet_address::to_string() calls fmt::format("{}", *this) anyway. However, the to_string() method is declared in .cc file, while formatter is in header and is equipeed with constexprs so that converting an address to string is done as much as possible compile-time. Also, though minor, fmt::to_string(foo) is believed to be even faster that fmt::format("{}", foo). |
The existing inet_address::to_string() calls fmt::format("{}", *this) anyway. However, the to_string() method is declared in .cc file, while form formatter is in the header and is equipeed with constexprs so that converting an address to string is done as much as possible compile-time. Also, though minor, fmt::to_string(foo) is believed to be even faster than fmt::format("{}", foo). Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
d7d330a
to
521a7c8
Compare
upd:
|
Regarding to_string() method. Having formatter is beneficial, because if you have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
🟢 CI State: SUCCESS✅ - Build Build Details:
|
The existing inet_address::to_string() calls fmt::format("{}", *this) anyway. However, the to_string() method is declared in .cc file, while form formatter is in the header and is equipeed with constexprs so that converting an address to string is done as much as possible compile-time.
Also, though minor, fmt::to_string(foo) is believed to be even faster than fmt::format("{}", foo).