From patchwork Wed Sep 7 00:45:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp904527wrt; Tue, 6 Sep 2022 17:47:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR6gArVoJ2aeRavlKi81Plig3xCVtU17vRQ7mA2DmjZSt3mRBmtfQ3231PEmZh2GMi6tVtEo X-Received: by 2002:a17:906:3a15:b0:73d:80bf:542c with SMTP id z21-20020a1709063a1500b0073d80bf542cmr652933eje.633.1662511652855; Tue, 06 Sep 2022 17:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662511652; cv=none; d=google.com; s=arc-20160816; b=AEyfYjrid2o08UTWkNXK8DxMg8QkCI3BT2+Z5+UWxZeynEwpikIsSN2WydF7poXWdW Fj4/rdy03c5XhqdryUBMIx2gAjh8AH66dnw0Kdue49HPxHdQEqcjpkilxF+08Eq976X0 o2SGBBp/MfEm4iqPQEBKCwa7aZNFm8r0nl0laF0hvLTotjhIlaYDMRq8Fu2tjabO7nX8 1YqI5OedpWMzBcGGBUEHyFpJG7KSZzhSGz9+6pMHkdLDT1auoixTifCs5Jhb9jJjEern DXicmGKG1ZBTxacK3g0XBRYO1fc4kSjXBzC4MKVG8MNa0vZ11p11IKdYzwJpyLjMMsmp UHVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=b4uZcVb1yB1//IU5rEE8/SASvFhEs8GgdRtORueOyJM=; b=ZDu2v+omiHqac+zS34NfxdR3h2hmJcsZbWPJw39OL1H79flhfMoWmT42duTKjL7ymZ Kq8VAKlASsF92sKsW4XoajsyyDoic3wxHDgNTlkaYH8tGKI9zrMIvlnIQXWihAupZSLl E+9NT/8viwjFP28QL7wLBHW8tFc13QWgV5ElrdMspTgfko5jFMsamcK7hzA7aMNaczyd ylxrbfVruto6dqBxvkvs0ReuLf9eJp/Ycxw+8OJQX10sBZcROxmvTjRbAkn48e8U8CEX tzwo6CdonOjZBFWBLd0th63J6O45RcaNqSLBVmnzvXgEK7A2Faz4DieQH6642ZJZbZBS vf2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fLyWFvR8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e9-20020a1709062d4900b0073dce13c643si9823621eji.872.2022.09.06.17.47.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 17:47:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fLyWFvR8; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 DFF1A383E057 for ; Wed, 7 Sep 2022 00:46:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFF1A383E057 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662511593; bh=b4uZcVb1yB1//IU5rEE8/SASvFhEs8GgdRtORueOyJM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=fLyWFvR81wujsadFlKDWNn2A56qFocHN07WjfVnMRK0nRtkW0e6n44htSiaKIL5je pUVZUG7OY01WV0Nces7GUL9jo+6hueOkVBsLSJPY+AOGj9Y3Znq4E66XGcRYgUTGLE jE2KfLV5cJwGh9yABmw/VEGu5HzAQtombWTvteNQ= 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 B2BC63858428 for ; Wed, 7 Sep 2022 00:45:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B2BC63858428 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-112-e4zD4v9iPXGH1hmZnS9ueA-1; Tue, 06 Sep 2022 20:45:47 -0400 X-MC-Unique: e4zD4v9iPXGH1hmZnS9ueA-1 Received: by mail-qt1-f198.google.com with SMTP id ci6-20020a05622a260600b0034370b6f5d6so10564696qtb.14 for ; Tue, 06 Sep 2022 17:45:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=b4uZcVb1yB1//IU5rEE8/SASvFhEs8GgdRtORueOyJM=; b=4G2/9T/AAU7jreroKKnAUgpckKEV4Mz9xYwH3zT2CgdQgpApKzUyPf4YxYC4oLuBRj 0dqeGnjOjzETjoUqrSFbKmGv61G2FlM8/Lz0p8nK1EzAVutgOuDnesARTfFXnQpGnVhl BTfgk1KmoCRXnuPIi9eVCeOJeqePsczN28E+rj70adO1Y8+LSaBebIU452I521ecGhHX ybYFNmIzTVC+snoozLjhX5Mu9IVuYVxCELGK6kTSUXSgOXoteLuEmnGqwUUosM51prGQ m3ORCjE3RxdAzEii/NuUyq0oEQQ/U8AmRY/2nu58Twwabfny50d2iGEyJ8k2U8qjbmPI Jvjw== X-Gm-Message-State: ACgBeo3MccU1hnwL/1+q8QfWquGNYGtbucJ2H1iJ9OcJY52i6FhmIiOu u2BOKRifiA5+OSQN5yJ9GOhRl5ywWyP88uiM5E7pf43Jt0Zd1e86NED8Od2Pt6vvo44etbOmIMZ g9kcMSZbHeMTAMDbytFV5oGOvVOEASqx69aGERAoYfKrYu/pukPzJBI2eQlYjgK+C+OI= X-Received: by 2002:a05:620a:454b:b0:6bb:63e1:7456 with SMTP id u11-20020a05620a454b00b006bb63e17456mr1058620qkp.328.1662511546775; Tue, 06 Sep 2022 17:45:46 -0700 (PDT) X-Received: by 2002:a05:620a:454b:b0:6bb:63e1:7456 with SMTP id u11-20020a05620a454b00b006bb63e17456mr1058608qkp.328.1662511546472; Tue, 06 Sep 2022 17:45:46 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id f1-20020a05620a408100b006bbd0ae9c05sm13811852qko.130.2022.09.06.17.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 17:45:46 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] libstdc++: Optimize is_void and is_null_pointer Date: Tue, 6 Sep 2022 20:45:41 -0400 Message-Id: <20220907004542.288365-1-ppalka@redhat.com> X-Mailer: git-send-email 2.37.3.518.g79f2338b37 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.0 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: 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org 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?1743269818433283069?= X-GMAIL-MSGID: =?utf-8?q?1743269818433283069?= Instead of defining these in terms of a helper class template and the relatively expensive __remove_cv_t, just declare four explicit specializations of the main template, one for each choice of cv-quals. Tested on x86_64-pc-linux-gnu, does this look OK for trunk? The is_void change alone reduces memory usage for join.cc by almost 1%. libstdc++-v3/ChangeLog: * include/std/type_traits (__is_void_helper): Remove. (is_void): Make the primary template derive from false_type, and define four explicit specializations that derive from true_type. (__is_null_pointer_helper, is_null_pointer): Likewise. --- libstdc++-v3/include/std/type_traits | 48 ++++++++++++++++++---------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index e4d167939d9..b83e7257a9f 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -289,23 +289,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // __remove_cv_t (std::remove_cv_t for C++11). template using __remove_cv_t = typename remove_cv<_Tp>::type; + /// @endcond // Primary type categories. - template - struct __is_void_helper + /// is_void + template + struct is_void : public false_type { }; template<> - struct __is_void_helper + struct is_void : public true_type { }; - /// @endcond - /// is_void - template - struct is_void - : public __is_void_helper<__remove_cv_t<_Tp>>::type - { }; + template<> + struct is_void + : public true_type { }; + + template<> + struct is_void + : public true_type { }; + + template<> + struct is_void + : public true_type { }; /// @cond undocumented template @@ -571,19 +578,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #define __cpp_lib_is_null_pointer 201309L - template - struct __is_null_pointer_helper + /// is_null_pointer (LWG 2247). + template + struct is_null_pointer : public false_type { }; template<> - struct __is_null_pointer_helper + struct is_null_pointer : public true_type { }; - /// is_null_pointer (LWG 2247). - template - struct is_null_pointer - : public __is_null_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + template<> + struct is_null_pointer + : public true_type { }; + + template<> + struct is_null_pointer + : public true_type { }; + + template<> + struct is_null_pointer + : public true_type { }; /// __is_nullptr_t (deprecated extension). /// @deprecated Non-standard. Use `is_null_pointer` instead.