public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc/devel/gccgo] libstdc++: std::includes performance tweak
Date: Sun, 12 Jul 2020 19:55:03 +0000 (GMT)	[thread overview]
Message-ID: <20200712195503.6E1323890402@sourceware.org> (raw)

https://gcc.gnu.org/g:465520e3eb45d83ad18394aa537150bfa6bdf117

commit 465520e3eb45d83ad18394aa537150bfa6bdf117
Author: Marc Glisse <marc.glisse@inria.fr>
Date:   Fri Jun 19 13:03:45 2020 +0100

    libstdc++: std::includes performance tweak
    
    A small tweak to the implementation of __includes, which in my
    application saves 20% of the running time. I noticed it because using
    range-v3 was giving unexpected performance gains.
    
    Some of the gain comes from pulling the 2 calls ++__first1 out of the
    condition so there is just one call. And most of the gain comes from
    replacing the resulting
    
    if (__comp(__first1, __first2))
      ;
    else
      ++__first2;
    
    with
    
    if (!__comp(__first1, __first2))
      ++__first2;
    
    I was very surprised that the code ended up being so different for such
    a change, and I still don't really understand where the extra time is
    going...
    
    Anyway, while I blame the compiler for not generating very good code
    with the current implementation, I believe the change can be seen as a
    simplification.
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/stl_algo.h (__includes): Simplify the code.

Diff:
---
 libstdc++-v3/include/bits/stl_algo.h | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h
index fd6edd0d5f4..550a15f2b3b 100644
--- a/libstdc++-v3/include/bits/stl_algo.h
+++ b/libstdc++-v3/include/bits/stl_algo.h
@@ -2783,15 +2783,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	       _Compare __comp)
     {
       while (__first1 != __last1 && __first2 != __last2)
-	if (__comp(__first2, __first1))
-	  return false;
-	else if (__comp(__first1, __first2))
-	  ++__first1;
-	else
-	  {
-	    ++__first1;
+	{
+	  if (__comp(__first2, __first1))
+	    return false;
+	  if (!__comp(__first1, __first2))
 	    ++__first2;
-	  }
+	  ++__first1;
+	}
 
       return __first2 == __last2;
     }


                 reply	other threads:[~2020-07-12 19:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200712195503.6E1323890402@sourceware.org \
    --to=ian@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).