-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Optimized string concatenation in _Tzdb_update_version()
#4577
Conversation
std::string s;
s.resize(33); // Avoid SSO
s = "😅";
std::cout << (const void*)s.data() << '\n';
auto s2 = std::move(s) + "🤣";
std::cout << (const void*)s2.data() << '\n';
However, changing |
Could ask for this explicitly with
Could fix this, and ask for NRVO by separating return statement: (_Icu_version += '.') += _STD to_string(_Num_leap_seconds);
return _Icu_version; But I doubt the value of optimizations here. |
this is right. |
_Tzdb_update_version()
Thanks! I pushed a commit to perform the concatenations on separate lines, since we conventionally don't perform multiple compound assignments on a single line. Overall, I think this change is reasonable - taking advantage of the NRVO, and using the single-character overload instead of the one for arbitrary C strings. This code is not actually exercised in normal usage (it's bypassed unless the registry reports new leap seconds that we don't know about), so I don't think this is worth extreme micro-optimization, but I'm okay with the change here. I manually tested this codepath since normal execution doesn't exercise it, and debugged into it to verify that the new code was getting picked up (i.e. verifying that I hadn't forgotten to
#include <chrono>
#include <print>
using namespace std;
using namespace std::chrono;
int main() {
const tzdb& db = get_tzdb();
println("Original version: {}", db.version);
println(" Updated version: {}", _Tzdb_update_version(db.version, 1729));
}
We merge changes to our GitHub and MSVC-internal repos simultaneously, using a semi-manual "mirroring" process. To save time, we batch up PRs. Your PR will be part of the next batch! I'll post comments here as I prepare that merge. |
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for making the codebase more consistent about using the Named Return Value Optimization, and congratulations on your first microsoft/STL commit! 🎉 😻 🚀 This change is expected to ship in VS 2022 17.11 Preview 2. |
No description provided.