diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-06-14 16:19:32 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-06-14 21:07:48 +0100 |
commit | 6abe341558abec40c9c44d76e7fb4fb3978e894b (patch) | |
tree | 70cced94b085f2c16a8eae9081e68db42407f5d1 /libgo | |
parent | 1b65779f46f16b4fffd0591f5e58722c1e7cde8d (diff) | |
download | gcc-6abe341558abec40c9c44d76e7fb4fb3978e894b.zip gcc-6abe341558abec40c9c44d76e7fb4fb3978e894b.tar.gz gcc-6abe341558abec40c9c44d76e7fb4fb3978e894b.tar.bz2 |
libstdc++: Check lengths first in operator== for basic_string [PR62187]
As confirmed by LWG 2852, the calls to traits_type::compare do not need
to be obsvervable, so we can make operator== compare string lengths
first and return immediately for non-equal lengths. This avoids doing a
slow string comparison for "abc...xyz" == "abc...xy". Previously we only
did this optimization for std::char_traits<char>, but we can enable it
unconditionally thanks to LWG 2852.
For comparisons with a const char* we can call traits_type::length right
away to do the same optimization. That strlen call can be folded away
for constant arguments, making it very efficient.
For the pre-C++20 operator== and operator!= overloads we can swap the
order of the arguments to take advantage of the operator== improvements.
libstdc++-v3/ChangeLog:
PR libstdc++/62187
* include/bits/basic_string.h (operator==): Always compare
lengths before checking string contents.
[!__cpp_lib_three_way_comparison] (operator==, operator!=):
Reorder arguments.
Diffstat (limited to 'libgo')
0 files changed, 0 insertions, 0 deletions