From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28962 invoked by alias); 19 Aug 2014 13:21:32 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 28913 invoked by uid 48); 19 Aug 2014 13:21:26 -0000 From: "glisse at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/62187] New: std::string==const char* could compare sizes first Date: Tue, 19 Aug 2014 13:21:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: glisse at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg01278.txt.bz2 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.