[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2022-06-14 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

Jonathan Wakely  changed:

   What|Removed |Added

   Target Milestone|--- |13.0
 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #20 from Jonathan Wakely  ---
Fixed for GCC 13.

[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2022-06-14 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

--- Comment #19 from CVS Commits  ---
The master branch has been updated by Jonathan Wakely :

https://gcc.gnu.org/g:1b65779f46f16b4fffd0591f5e58722c1e7cde8d

commit r13-1095-g1b65779f46f16b4fffd0591f5e58722c1e7cde8d
Author: Jonathan Wakely 
Date:   Tue Jun 14 14:54:27 2022 +0100

libstdc++: Inline all basic_string::compare overloads [PR59048]

Defining the compare member functions inline allows calls to
traits_type::length and std::min to be inlined, taking advantage of
constant expression arguments. When not inline, the compiler prefers to
use the explicit instantiation definitions in libstdc++.so and can't
take advantage of constant arguments.

libstdc++-v3/ChangeLog:

PR libstdc++/59048
* include/bits/basic_string.h (compare): Define inline.
* include/bits/basic_string.tcc (compare): Remove out-of-line
definitions.
* include/bits/cow_string.h (compare): Define inline.
* testsuite/21_strings/basic_string/operations/compare/char/3.cc:
New test.

[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2022-06-14 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

Jonathan Wakely  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |redi at gcc dot gnu.org
 Status|NEW |ASSIGNED

[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2021-02-12 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

--- Comment #18 from Jonathan Wakely  ---
We don't create a copy.

[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2021-02-11 Thread hiraditya at msn dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

AK  changed:

   What|Removed |Added

 CC||hiraditya at msn dot com

--- Comment #17 from AK  ---
Now that we have string_view, will it be possible to avoid creating a copy?

[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2017-05-18 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

Martin Sebor  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Status|UNCONFIRMED |NEW
   Last reconfirmed|2013-11-08 00:00:00 |2017-05-19
 CC||msebor at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #16 from Martin Sebor  ---
Confirmed.

I don't think the char* overload can ever match the string overload because the
former has to compute the length of the char* argument and (possibly also)
compare the strings, while the latter can avoid the first step because the
lengths of both arguments are precomputed.

But the char* overload can be sped up by avoiding string::compare which always
traverses the strings, when operator== only has to do that if their lengths are
the same.

It also doesn't help that string::compare is not expanded inline (because
std::string is declared extern).

In my tests, the following definition speeds the operator up by a factor of 5,
making it about 20% faster than strcmp:

  template
inline bool
operator==(const basic_string<_CharT>& __lhs,
const _CharT* __rhs)
  {
return !__lhs.compare (__rhs);

typedef typename basic_string<_CharT>::size_type size_type;
const size_type __len1 = __lhs.length ();
const size_type __len2 = __builtin_strlen (__rhs);

return __len1 == __len2
  && !char_traits<_CharT>::compare (__lhs.data (), __rhs,
__len1 < __len2 ? __len1 : __len2);
  }

[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2015-06-03 Thread manu at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

Manuel López-Ibáñez manu at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 CC||manu at gcc dot gnu.org
 Resolution|--- |DUPLICATE

--- Comment #14 from Manuel López-Ibáñez manu at gcc dot gnu.org ---
Let's mark it as a duplicate then.

*** This bug has been marked as a duplicate of bug 43052 ***

[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2015-06-03 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

Marc Glisse glisse at gcc dot gnu.org changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|DUPLICATE   |---

--- Comment #15 from Marc Glisse glisse at gcc dot gnu.org ---
(In reply to Ondrej Bilka from comment #13)
 Yes, this is duplicate of following.
 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052

No it isn't. I made a comment related to that other PR, but IIRC the main point
here is that the function is not pulled out of the loop, which is independent
of how memcmp gets expanded.


[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2015-06-02 Thread neleai at seznam dot cz
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

Ondrej Bilka neleai at seznam dot cz changed:

   What|Removed |Added

 CC||neleai at seznam dot cz

--- Comment #13 from Ondrej Bilka neleai at seznam dot cz ---
Yes, this is duplicate of following.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
Until thats fixed you should compile everything with -fno-builtin-strcmp
-fno-builtin-memcmp


[Bug libstdc++/59048] operator== between std::string and const char* slower than strcmp

2014-01-09 Thread glisse at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59048

Marc Glisse glisse at gcc dot gnu.org changed:

   What|Removed |Added

 Status|WAITING |UNCONFIRMED
Version|4.4.7   |4.9.0
Summary|std::string operator==  |operator== between
   |between std::string and |std::string and const char*
   |const char* creates |slower than strcmp
   |unecessary temporary object |
 Ever confirmed|1   |0

--- Comment #12 from Marc Glisse glisse at gcc dot gnu.org ---
Configuring libstdc++ with --disable-extern-template fixes the issue (I
actually only edited bits/c++config.h).

I don't think we can mark the functions with attribute pure, and even if we do
it doesn't seem sufficient (not sure what else gcc wants).