[PATCH] libstdc++: Optimize operator+(string/char*, string/char*) equally
Jonathan Wakely
jwakely@redhat.com
Wed Aug 24 14:24:11 GMT 2022
On Wed, 24 Aug 2022 at 07:17, Will Hawkins wrote:
>
> Until now operator+(char*, string) and operator+(string, char*) had
> different performance characteristics. The former required a single
> memory allocation and the latter required two. This patch makes the
> performance equal.
>
> libstdc++-v3/ChangeLog:
There should be a blank line here.
> * libstdc++-v3/include/bits/basic_string.h (operator+(string, char*)):
The path should be relative to the ChangeLog, so should not include
the libstdc++-v3/ directory component. You can use the git gcc-verify
alias to check your commit msgs format before submitting. That runs
the same checks as will be used for the server-side hook that decides
whether to allow a push. See the customization script described at
https://gcc.gnu.org/gitwrite.html#vendor for the alaises.
Also, the overload you're changing is operator+(const string&, const
char*). The distinction matters, because there is also
operator+(string&&, const char*) and what you wrote looks more like
that one.
So I've committed it with this changelog:
libstdc++-v3/ChangeLog:
* include/bits/basic_string.h (operator+(const string&,
const char*)):
Remove naive implementation.
* include/bits/basic_string.tcc (operator+(const string&,
const char*)):
Add single-allocation implementation.
Thanks for the patch!
More information about the Libstdc++
mailing list