From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D4ED1385803E for ; Thu, 1 Sep 2022 19:33:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D4ED1385803E Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-n2C9vl_JOiGtSX6waoFc8A-1; Thu, 01 Sep 2022 15:33:47 -0400 X-MC-Unique: n2C9vl_JOiGtSX6waoFc8A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0E8A91C07592; Thu, 1 Sep 2022 19:33:47 +0000 (UTC) Received: from localhost (unknown [10.33.36.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB50EC15BB3; Thu, 1 Sep 2022 19:33:46 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Optimize std::decay Date: Thu, 1 Sep 2022 20:33:46 +0100 Message-Id: <20220901193346.352596-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Sep 2022 19:33:50 -0000 Tested powerpc64le-linux, pushed to trunk. -- >8 -- Define partial specializations of std::decay and its __decay_selector helper so that remove_reference, is_array and is_function are not instantiated for every type, and remove_extent is not instantiated for arrays. libstdc++-v3/ChangeLog: * include/std/type_traits (__decay_selector): Add partial specializations for array types. Only check for function types when not dealing with an array. (decay): Add partial specializations for reference types. --- libstdc++-v3/include/std/type_traits | 39 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index e4b9b59ce08..639c351df8a 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -2203,34 +2203,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Decay trait for arrays and functions, used for perfect forwarding // in make_pair, make_tuple, etc. - template::value, - bool _IsFunction = is_function<_Up>::value> - struct __decay_selector; - - // NB: DR 705. template - struct __decay_selector<_Up, false, false> - { typedef __remove_cv_t<_Up> __type; }; + struct __decay_selector + : __conditional_t::value, // false for functions + remove_cv<_Up>, // N.B. DR 705. + add_pointer<_Up>> // function decays to pointer + { }; + + template + struct __decay_selector<_Up[_Nm]> + { using type = _Up*; }; template - struct __decay_selector<_Up, true, false> - { typedef typename remove_extent<_Up>::type* __type; }; + struct __decay_selector<_Up[]> + { using type = _Up*; }; - template - struct __decay_selector<_Up, false, true> - { typedef typename add_pointer<_Up>::type __type; }; /// @endcond /// decay template - class decay - { - typedef typename remove_reference<_Tp>::type __remove_type; + struct decay + { using type = typename __decay_selector<_Tp>::type; }; - public: - typedef typename __decay_selector<__remove_type>::__type type; - }; + template + struct decay<_Tp&> + { using type = typename __decay_selector<_Tp>::type; }; + + template + struct decay<_Tp&&> + { using type = typename __decay_selector<_Tp>::type; }; /// @cond undocumented -- 2.37.2