]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: store the length after the store of the null character
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Tue, 18 Nov 2025 20:57:24 +0000 (12:57 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 19 Nov 2025 17:14:05 +0000 (09:14 -0800)
commit47ebad54abc127934693e7ace75a3cb08d6bc36c
tree07b4e80d9de59805893ed46853fee3411244c84b
parentc8eb7d8dbb9ff4eb13f476b16f8f58103cace64e
libstdc++: store the length after the store of the null character

This improves the code generation slightly for std::string because of
aliasing. In many cases the length will be read again and the store of
the null character will cause the length to be re-read due to aliasing
requirements of the char type. So swapping around the stores will allow
the length not to have to be reloaded from memory and will allow
for more optimizations.

Bootstrapped and tested on x86_64-linux-gnu.

libstdc++-v3/ChangeLog:

* include/bits/basic_string.h (basic_string::M_set_length): Swap
around the order of traits_type::assign and _M_length so that
_M_length is at the end.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
libstdc++-v3/include/bits/basic_string.h