From patchwork Tue Nov 29 17:14:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 27384 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp466697wrr; Tue, 29 Nov 2022 09:16:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf6CzT1c41KMoqWY+rYw1yv2yPBbojTifIsbdrlRT1QoPk8N8eUo54WsR+d5bKt9jB/MTJso X-Received: by 2002:a17:906:8493:b0:7be:a769:2f41 with SMTP id m19-20020a170906849300b007bea7692f41mr11794482ejx.690.1669742196811; Tue, 29 Nov 2022 09:16:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669742196; cv=none; d=google.com; s=arc-20160816; b=e9Bji3V1YQIIwoCW1YNzDtNcbOirIUIULsqPe0vkcIIBMixViy1aSxuFIvWmNJl+DQ lGkFxPYzOlHbWbaLtTpMnF4C2hlyOeypfexXqkrVcG3jEtOlrJEE1ldx0I1G6YW73rw0 HQ8NgWgoCYwrwrzH0FR6HTZgJINHdVVi3R6NshuWy26dHLKDgJ/AkDszGsXJDammaWAH aKNj0t3b8W8ZXhqsy37mNyrmO7hPKeeBIG/9OVpmuL3FseSCxmW1HgkFElz63oTa1yhi TiPHxVzym9jSHb4Vf4q9wuCxdU90aYvowlJuq5rnJsRotmrc8Y4AdEi06sbQQY4avKYJ mxNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=/WhSZwGkM3tWh4wOVNMg0twDbDwLs/uxFZ/LSX/TgPs=; b=r63lryz1N/VSfc9TNtDc5mnhD36AUeZf/7Tf73Ph0tpLqvHuza8F9z2/CuDy0vKMn4 BwleWSeiVGOTu/Kb5ncTmEzCdLxkxYP6eNoMibWKHMmm0zcegWVAxW6BofPc79Sseg8Z dDp5S51WA7kZ9ZojZ2PxoGYisSuISirixEByQH+y9pHhdorSbr+ZXBCfU+Xa6VGK8kSc KI7E88RVghl2volHz74QPFdhgL4A9niugO9bDe1yQN7ILzy/HOUhGOwpIo0imfX8nb48 l192RawWLjJM8gx3Wd2CBvE8pWGdIXNsWJZa85TyaKBpCUOEX69ObBzgxOASRNAjBgg9 I5UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UmmwdFzE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dn6-20020a17090794c600b007c08b7d496esi1622680ejc.562.2022.11.29.09.16.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 09:16:36 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UmmwdFzE; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7E0D0384F8AF for ; Tue, 29 Nov 2022 17:15:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E0D0384F8AF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669742133; bh=/WhSZwGkM3tWh4wOVNMg0twDbDwLs/uxFZ/LSX/TgPs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UmmwdFzElhggGY7mWL5jun2LchIuHThEuS/lM64oIaFRqZmFjhDbv/M+dPICQTzAC sNZFcXjNl3atZY11cEcy4DbBg1KzJfAXdj5Vs7EhRPfDWOiVtyInhZRASCpKLT2Q7d Lan6V/9RfE6Uh/7j/CTQvSAAXPpH9ZXJggR9LpSM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C3DCA3854541 for ; Tue, 29 Nov 2022 17:14:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C3DCA3854541 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-85-h3bA7RP4NH-OoLfVD9p_ww-1; Tue, 29 Nov 2022 12:14:43 -0500 X-MC-Unique: h3bA7RP4NH-OoLfVD9p_ww-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 59B99101246A; Tue, 29 Nov 2022 17:14:35 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 215432024CBF; Tue, 29 Nov 2022 17:14:35 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Remove unnecessary tag dispatching in std::vector Date: Tue, 29 Nov 2022 17:14:32 +0000 Message-Id: <20221129171432.149718-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750851594200236983?= X-GMAIL-MSGID: =?utf-8?q?1750851594200236983?= Tested x86_64-linux. Pushed to trunk. -- >8 -- There's no need to call a _M_xxx_dispatch function with a statically-known __false_type tag, we can just directly call the function that should be dispatched to. This will compile a tiny bit faster and save a function call with optimization or inlining turned off. Also add the always_inline attribute to the __iterator_category helper used for dispatching on the iterator category. libstdc++-v3/ChangeLog: * include/bits/stl_iterator_base_types.h (__iterator_category): Add always_inline attribute. * include/bits/stl_vector.h (assign(Iter, Iter)): Call _M_assign_aux directly, instead of _M_assign_dispatch. (insert(const_iterator, Iter, Iter)): Call _M_range_insert directly instead of _M_insert_dispatch. --- libstdc++-v3/include/bits/stl_iterator_base_types.h | 1 + libstdc++-v3/include/bits/stl_vector.h | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_iterator_base_types.h b/libstdc++-v3/include/bits/stl_iterator_base_types.h index 9eecd1dd855..5d90c0d8ea7 100644 --- a/libstdc++-v3/include/bits/stl_iterator_base_types.h +++ b/libstdc++-v3/include/bits/stl_iterator_base_types.h @@ -233,6 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * sugar for internal library use only. */ template + __attribute__((__always_inline__)) inline _GLIBCXX_CONSTEXPR typename iterator_traits<_Iter>::iterator_category __iterator_category(const _Iter&) diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index b4ff3989a5d..e87fab0e51c 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -821,7 +821,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _GLIBCXX20_CONSTEXPR void assign(_InputIterator __first, _InputIterator __last) - { _M_assign_dispatch(__first, __last, __false_type()); } + { _M_assign_aux(__first, __last, std::__iterator_category(__first)); } #else template void @@ -1478,8 +1478,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _InputIterator __last) { difference_type __offset = __position - cbegin(); - _M_insert_dispatch(begin() + __offset, - __first, __last, __false_type()); + _M_range_insert(begin() + __offset, __first, __last, + std::__iterator_category(__first)); return begin() + __offset; } #else