From patchwork Fri Aug 23 12:40:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1976038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Pfs9rU/a; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wr07M67P5z1yNm for ; Fri, 23 Aug 2024 22:41:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD0D2386F47A for ; Fri, 23 Aug 2024 12:41:33 +0000 (GMT) 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 ESMTP id 58B253861807 for ; Fri, 23 Aug 2024 12:41:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58B253861807 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 58B253861807 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724416863; cv=none; b=n/mFDN8hc7k++v3Sd/gerfKo3h4Dbo5M5jUenwsdldepkdpN/8F14yqzaK8Mw9EblEQUfVLutEemS3m3cpr9ocl+dC7uhcRJJv98aoa8fJp1EMwGYKxPFV4a9NEhYHkcpNS7u10Y/b3XUNVa5eEqUdJez5iTMl0CIDazUqamJ5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724416863; c=relaxed/simple; bh=yejLAY3zuHk1Ab6846T348dPuyRpk5lvyIjXPQcAxwI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jlFLu7ZCB3F7I8o/4DoisRLDSWY9uhHqRoBh1Z0nTtud3wCmKMAvceyh18drDuZxbRCX6oJWwxr8DJHELXwXtUCW49JODq1ZO9/88JgT6Xlwk49Ag7KkEHER8A2V8rmS0dKxeeuy1m+/42/RYudXF+5ipmLDSFDR51bdjZXPxpc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724416861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lozJ8J9OdaVZ/rXf1s+IGZV9l7B9gHL9tQrENsI7Y5M=; b=Pfs9rU/a81EINIXru+X2WkD+yPp3t8Hu0C4wjZVU9cHg/r7AfVZ3s8dwWEm+rdzGH/ejl4 0bt0HMQpSiZqaC3UBcauKvzp9krOBTkulzwYH4DDQG2AtAdb+9KUdUAsAz1EhXTkByuJ6U 7FSptXcNkoE0vyUccRM3Ldp9TiGmBoE= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-486-uiI-JiGuNayj9ieKnIaB7w-1; Fri, 23 Aug 2024 08:40:59 -0400 X-MC-Unique: uiI-JiGuNayj9ieKnIaB7w-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BDDE019560A2; Fri, 23 Aug 2024 12:40:57 +0000 (UTC) Received: from localhost (unknown [10.42.28.41]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E993F19560A3; Fri, 23 Aug 2024 12:40:56 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed,v2] libstdc++: Optimize __try_use_facet for const types Date: Fri, 23 Aug 2024 13:40:29 +0100 Message-ID: <20240823124055.964684-1-jwakely@redhat.com> In-Reply-To: <20240801213927.388966-5-jwakely@redhat.com> References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- LWG 436 confirmed that const-qualified types are valid arguments for Facet template parameters (but volatile-qualified types are not). Use the fast path in std::use_facet and std::has_facet for const T as well as T. libstdc++-v3/ChangeLog: * include/bits/locale_classes.tcc (__try_use_facet): Also avoid dynamic_cast for const-qualified facet types. --- libstdc++-v3/include/bits/locale_classes.tcc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/locale_classes.tcc b/libstdc++-v3/include/bits/locale_classes.tcc index c79574e58de..d5ef1911057 100644 --- a/libstdc++-v3/include/bits/locale_classes.tcc +++ b/libstdc++-v3/include/bits/locale_classes.tcc @@ -110,7 +110,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // We know these standard facets are always installed in every locale // so dynamic_cast always succeeds, just use static_cast instead. #define _GLIBCXX_STD_FACET(...) \ - if _GLIBCXX_CONSTEXPR (__is_same(_Facet, __VA_ARGS__)) \ + if _GLIBCXX_CONSTEXPR (__is_same(const _Facet, const __VA_ARGS__)) \ return static_cast(__facets[__i]) _GLIBCXX_STD_FACET(ctype);