From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1059) id AB59E3892446; Mon, 29 Jun 2020 21:09:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB59E3892446 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1593464973; bh=f6gco5kQGOpb5G5W9Q9bZkRID9zPnRVfyoHlwuKL+eA=; h=From:To:Subject:Date:From; b=ZjVkoqBmWXbE7WdyFdxyp5/2TzGhB/E3L/O1SipUxrd1mBWnQjaDeESq8EU3Zpvrq rpKiHtln9uGn75ggSuqB3wGc9ujIfjbgFT8+ieExNN/NKGK65e0Aqeio995QrZEzIo pvwSau+Qg38yCehu1ZNoJhUJJEWr5WpL5ve4pz2M= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Nathan Sidwell To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/c++-modules] libstdc++: std::includes performance tweak X-Act-Checkin: gcc X-Git-Author: Marc Glisse X-Git-Refname: refs/heads/devel/c++-modules X-Git-Oldrev: f8f5715606a4a455327874847ccc91f4617bb4de X-Git-Newrev: 465520e3eb45d83ad18394aa537150bfa6bdf117 Message-Id: <20200629210933.AB59E3892446@sourceware.org> Date: Mon, 29 Jun 2020 21:09:33 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2020 21:09:33 -0000 https://gcc.gnu.org/g:465520e3eb45d83ad18394aa537150bfa6bdf117 commit 465520e3eb45d83ad18394aa537150bfa6bdf117 Author: Marc Glisse 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; }