aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2023-08-14 11:56:55 +0100
committerJonathan Wakely <jwakely@redhat.com>2023-08-17 20:24:17 +0100
commit51ec07b116b802d845d762beddf8b98e8c0e32ab (patch)
tree0c89a79a3569473251780aae0b0233d479c9af06 /gcc/rust
parent95c2b0cc9eaa5b9fbec34e8c5399c7d8f07f329b (diff)
downloadgcc-51ec07b116b802d845d762beddf8b98e8c0e32ab.zip
gcc-51ec07b116b802d845d762beddf8b98e8c0e32ab.tar.gz
gcc-51ec07b116b802d845d762beddf8b98e8c0e32ab.tar.bz2
libstdc++: Optimize std::to_string using std::string::resize_and_overwrite
This uses std::string::__resize_and_overwrite to avoid initializing the string buffer with characters that are immediately overwritten. This results in about 6% better performance for the std_to_string case in int-benchmark.cc from https://github.com/fmtlib/format-benchmark This requires a change to a testcase. The previous implementation guaranteed that the string returned from std::to_string(integral-type) would have no excess capacity, because it was constructed with the correct length. The new implementation constructs an empty string and then resizes it with resize_and_overwrite, which over-allocates. This means that the "no-excess capacity" guarantee no longer holds. We can also greatly improve the performance of std::to_wstring by using std::to_string and then widening it with a new helper function, instead of using std::swprintf to do the formatting. libstdc++-v3/ChangeLog: * include/bits/basic_string.h (to_string(integral-type)): Use resize_and_overwrite when available. (__to_wstring_numeric): New helper functions. (to_wstring): Use std::to_string then __to_wstring_numeric. * testsuite/21_strings/basic_string/numeric_conversions/char/to_string_int.cc: Remove check for no excess capacity.
Diffstat (limited to 'gcc/rust')
0 files changed, 0 insertions, 0 deletions