[PATCH] Improve string::clear() performance

Jonathan Wakely jwakely@redhat.com
Wed Sep 14 11:06:00 GMT 2016


On 13/09/16 11:02 -0700, Cong Wang wrote:
>In !_GLIBCXX_USE_CXX11_ABI implementation, string::clear() calls
>_M_mutate(), which could allocate memory as we do COW. This hurts
>performance when string::clear() is on the hot path.
>
>This patch improves it by using _S_empty_rep directly when
>_GLIBCXX_FULLY_DYNAMIC_STRING is not enabled. And Linux distro like
>Fedora doesn't enable this, this is why we caught it.
>
>The copy-and-clear test shows it improves by 50%.
>
>Ran all testsuites on Linux-x64.

Thank you for the patch (and changelog and test results!).

Do you have a GCC copyright assignment in place? See
https://gcc.gnu.org/contribute.html#legal for details.

If I understand the purpose of the change correctly, it's similar to
https://gcc.gnu.org/ml/gcc-patches/2014-06/msg00278.html - is that
right?



More information about the Libstdc++ mailing list