From patchwork Wed Jul 10 21:11:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1959021 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=ckn/OvHU; 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 4WK9Y669kpz1xqc for ; Thu, 11 Jul 2024 07:12:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 028363841FD2 for ; Wed, 10 Jul 2024 21:12:25 +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 ESMTPS id C0D393870859 for ; Wed, 10 Jul 2024 21:11:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0D393870859 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 C0D393870859 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=1720645920; cv=none; b=pQ06pv3kZC1eylveA67NYiWo+fqmMwIuNxr9GWtVRWtXGiSX2F4A1s71c055Mg5W14nexn196VfPLKzv+TL7sSpiKwq+Nk3oOpH6o8wNgzk3IsvAx3BVtyyDREo5irhx6BqzF6EdKbK+h6OaUWC4Geb+ZoauqyxM6TkAB3WbI74= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720645920; c=relaxed/simple; bh=sNUxUli4dA21LJwdiy6+aU9dXQlzNpCOeCgg0B3Zibo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bck+UXxfn7FhIBSk4cQY4iLi0NUHDckeXggyabqgrVp4GGGoHVWkmchFfEnDfjFsDKA6zGH9ot8GIDIdl3B/hataw6eLIO93MeDa6RL7Wv2kKxXbnNhYYuf2jAkoAWYNv0v7xaEy1RQ0dmboZc5LniCHDsZnYE0fLWlx3VsDBLI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720645919; 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; bh=nKj7HD8Lsx1yxRq0wDPTVWzTcxKmlYy+CtBmraYF3W8=; b=ckn/OvHUiq+TwQ/DJEIUjoTnKsTlfCCOEWSF3LC8+IUHXaRLTmVMbn/yFO/P0UqNEeKebW PUY91t6g0BvcRDlSkJtwYRgkN7WiXpbDq/AT2A06kqhr05Gvi9Y42qoPmM9Y+QwSz30/QN lswTpNOxINsnLSjkNi+YsnyI1eBLsl4= Received: from mx-prod-mc-03.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-340-StzgJzrcNxy0yxHAyqpN0g-1; Wed, 10 Jul 2024 17:11:58 -0400 X-MC-Unique: StzgJzrcNxy0yxHAyqpN0g-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E714319560AB; Wed, 10 Jul 2024 21:11:56 +0000 (UTC) Received: from localhost (unknown [10.42.28.19]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0466D1955F40; Wed, 10 Jul 2024 21:11:55 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Minor optimization for std::locale::encoding() Date: Wed, 10 Jul 2024 22:11:36 +0100 Message-ID: <20240710211154.918535-1-jwakely@redhat.com> 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=-12.1 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, SPF_HELO_NONE, SPF_NONE, TXREP 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 -- For the C locale we know the encoding is ASCII, so we can avoid using newlocale and nl_langinfo_l. Similarly, for an unnamed locale, we aren't going to get a useful answer, so we can just use a default-constrcuted std::text_encoding representing an unknown encoding. libstdc++-v3/ChangeLog: * src/c++26/text_encoding.cc (__locale_encoding): Add to unnamed namespace. (std::locale::encoding): Optimize for "C" and "*" names. --- libstdc++-v3/src/c++26/text_encoding.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/src/c++26/text_encoding.cc b/libstdc++-v3/src/c++26/text_encoding.cc index b9a50ef1a00..efe2997562a 100644 --- a/libstdc++-v3/src/c++26/text_encoding.cc +++ b/libstdc++-v3/src/c++26/text_encoding.cc @@ -36,7 +36,9 @@ namespace std { _GLIBCXX_BEGIN_NAMESPACE_VERSION - +namespace +{ +// Attempt to determine the text_encoding used by the named locale. text_encoding __locale_encoding(const char* name) { @@ -54,6 +56,7 @@ __locale_encoding(const char* name) return enc; } +} // namespace _GLIBCXX_END_NAMESPACE_VERSION } // namespace std @@ -87,8 +90,15 @@ std::text_encoding::_M_is_environment() const std::text_encoding std::locale::encoding() const { - return std::__locale_encoding(name().c_str()); + string name = this->name(); + if (name.length() == 1) + { + if (name[0] == 'C') + return text_encoding(text_encoding::ASCII); + if (name[0] == '*') + return {}; + } + return __locale_encoding(name.c_str()); } #endif // CHAR_BIT == 8 - #endif // _GLIBCXX_USE_NL_LANGINFO_L