public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/62187] New: std::string==const char* could compare sizes first
@ 2014-08-19 13:21 glisse at gcc dot gnu.org
  2022-06-14 14:58 ` [Bug libstdc++/62187] " redi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-08-19 13:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62187

            Bug ID: 62187
           Summary: std::string==const char* could compare sizes first
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org

Hello,

when I compare 2 basic_string with ==, libstdc++ only uses the optimization of
first checking that the sizes are the same (before calling compare) if
__is_char<_CharT> and the traits and allocator are the default ones. I don't
understand why, but assuming there is a good reason, I believe the optimization
should still apply when comparing std::string and const char*.

(this applies to __vstring as well)

This was noticed in PR 62156, where we also see that std::string("foo") does a
memcpy of size 3 then sets the 4th char to '\0', where a single memcpy of size
4 would make sense.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-14 20:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-19 13:21 [Bug libstdc++/62187] New: std::string==const char* could compare sizes first glisse at gcc dot gnu.org
2022-06-14 14:58 ` [Bug libstdc++/62187] " redi at gcc dot gnu.org
2022-06-14 20:19 ` cvs-commit at gcc dot gnu.org
2022-06-14 20:20 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).