From patchwork Thu Sep 1 19:33:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 910 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp399546wro; Thu, 1 Sep 2022 12:38:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR7tsJHWPZpqI/5Gv2mXz+KHF6MsIzpNhcGrc5stgfR69n/63sUWNTd5JpSfbnaHCdfnZK62 X-Received: by 2002:a17:907:7215:b0:741:416f:fb59 with SMTP id dr21-20020a170907721500b00741416ffb59mr19101022ejc.150.1662061105591; Thu, 01 Sep 2022 12:38:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662061105; cv=none; d=google.com; s=arc-20160816; b=YgEusX38OcuAlMemb6t+suh+ApEv+//lceRgtWlyR70Ai8D3oUruLH9QuhfPFFQOmk zDWKQKs9+ZfkNAJT8xWbDnU19yne7jJdCn1WqS81oZi236f8hCGYTtU6yUvYS08cJrO8 i2f1s7GzzZEC8rm2X70PQwA2s3BM19NLY6lkKdcHucvneVirhV7HVFmp+EeHuQeDmupv B3x8A2JttdNuMCho9sb2aHPK7b4ET/WjVHBc6UcfHkyNKXtoWVbLCDrkZOtR56jsd0ak phL+Vgxs2LLgagRFxQRKjthkdLKNicuS6f6tsQD+ZM0TSodLcco4BsuK4qrLFYMupXEL BqCQ== 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=LTX/ioYxPl7g0s7kr7tI+toChgoL0kcW+O7e5+L4xdg=; b=QN9HUWSN566CHkAnMJu7BXnxXwMK2Q0aIL4XEReujJCSzI9TS6jKm5gL6EeLNyi1cu bfIMQgZMPXMLvN0Qke2Q4kTWMp/BjPe3CVGMPqcJV6hyqY8kI4wdmu3AXoh4JlMk2637 ge1+vBStIaBrYqtDKznlNCeD4/UFfLB6zjULM5Guz1Kzqyr6O8hBLQH6akerYhydDP2z k+Tq2HAYf7I7U4nqT/o9tLlzkgYOk+NnYO0ayKbMdHBI9zoq3eOxexQfyQ0rJEPzZfan mhhIkIBXpgUx0u3uPdTgXa9r/2CZ6Qa1klRNzDDGv/Q9rQ4BLXRA/LvrKa4z83HRfRnQ BXCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="d/Sj1U79"; 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 x23-20020a1709065ad700b0073156c8777asi38958ejs.894.2022.09.01.12.38.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 12:38:25 -0700 (PDT) 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="d/Sj1U79"; 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 A9BC138286FE for ; Thu, 1 Sep 2022 19:36:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9BC138286FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662060978; bh=LTX/ioYxPl7g0s7kr7tI+toChgoL0kcW+O7e5+L4xdg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=d/Sj1U79FQXDFQ2ZBJweVCoFZiLl7nGJ9+tx92yGi0xik0OvRlIgGovdiZgZe8R83 8pDxHa/J/LtD20RPZeLenhg1T7BZbBCSU2ijVo0tGvqCLcLXAAV8XxJSB/Y4gwMvJI eL549MWgPTl7q0Pc+xhmXHBoI7EwKuyP8wan8afo= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id AEBE13857C6F for ; Thu, 1 Sep 2022 19:33:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AEBE13857C6F 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) 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 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=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?1742797385624724405?= X-GMAIL-MSGID: =?utf-8?q?1742797385624724405?= 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