From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112306 invoked by alias); 24 Aug 2017 11:26:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 112286 invoked by uid 89); 24 Aug 2017 11:26:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-21.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_INFOUSMEBIZ,KAM_LAZY_DOMAIN_SECURITY,RDNS_DYNAMIC autolearn=ham version=3.3.2 spammy=HTo:U*libstdc, H*MI:ptr, H*MI:info, pay X-Spam-User: qpsmtpd, 2 recipients X-HELO: void-ptr.info Received: from pppoe.185.44.68.223.lanport.ru (HELO void-ptr.info) (185.44.68.223) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Aug 2017 11:26:31 +0000 Received: from ptr by void-ptr.info with local (Exim 4.72) (envelope-from ) id 1dkqHM-0008So-TP; Thu, 24 Aug 2017 14:26:28 +0300 Message-Id: From: Petr Ovtchenkov Date: Thu, 24 Aug 2017 11:34:00 -0000 Subject: [PATCH] copy_n for input iterator, avoid in-loop jumps To: libstdc++@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg01431.txt.bz2 Reword loop in copy_n specialization for input iterator. Avoid condition check and jumps within loop. Pay attention that input iterator incremented n - 1 times, while output iterator incremented n times. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50119 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81857 --- libstdc++-v3/include/bits/stl_algo.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index c2ac031..bf043cd 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -757,17 +757,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _OutputIterator __result, input_iterator_tag) { if (__n > 0) - { - while (true) - { - *__result = *__first; - ++__result; - if (--__n > 0) - ++__first; - else - break; - } - } + { + *__result = *__first; + ++__result; + --__n; + } + for (; __n > 0; --__n) + { + ++__first; + *__result = *__first; + ++__result; + } return __result; } -- 2.10.1