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.

Reply via email to