From patchwork Tue Jan 9 17:20:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 186511 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp309543dyi; Tue, 9 Jan 2024 10:41:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2OmeEuxJiACmtN1E0nuGjtW+2tlGedX+mQZQqRnVTO99qGeufj3rktkrT6ZZiNlUlZcVt X-Received: by 2002:a05:6808:1481:b0:3bd:446c:a65d with SMTP id e1-20020a056808148100b003bd446ca65dmr347859oiw.90.1704825679796; Tue, 09 Jan 2024 10:41:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704825679; cv=pass; d=google.com; s=arc-20160816; b=dtkFNONwZ4NB2+PqNUvxcIs4r8tewc4JZ70GDh29EkYvs3NmmuRInBuG8jIMsS/Bz1 luUijqYpKukvxD80IlFWf6wW2JqZWh1BdlVwLrWVQQ2Orn2V1nSVTi8axLw2GXcs5m8C O+A+DWpQL5zk3jgO9SD6qBvWu43G+woBTB0pIoIsAGpn0E6iG51noCrmdBIX2pgyvHDu PKxrc99bHz55ddzfSK0SI8lWxPzaCMWu2HioRrgjZfK2FIexZvqFyGPMnMOGM2jtzX7S B4gKiP2b0RlVasBRevV0fbvnsJ/5AbzDVFmjLnZ46zsnXfEFKN7ftULxZVRtxS6NKQI7 RKTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=mgNkoD57GSGHy8L6mQc/pBvruLkSKBv0+XXBu2u4JcU=; fh=sJ+2/4g29YdyXkoRrFZSpsL2zxijepB7X/1rB0LDDh8=; b=b8DBUOubvzNJOnjMS2chAfOaxA0B1Ii5+NyYi9IB1pujInGcYiM8oil9L3AxHxHo5B UESM06P06hl7rD7UvIM4KJQC2Kb0jtFlWQaJDOt3wZEh81hKiUP1QritO+GX6X1PZogG yGQtVDhSAlMz8i/mJ6WPAjcmEfhVUL77QlvO8e2uc7lfHkdOHPDu9h8hliiIW4otD7jZ xWG7gbldp3xbo/G+/NZyFou2AyLqIqyn/BFPJXW6DCWvouHdv/Dnj+GIY2caBkK5DLSX FCwPBIbEPXWMZXWypfYBDoC2WmtWJDjbkRtkhe9KA0ScPL320ZSmhLmx43izMSzxcplL nhmg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZAM3WLN7; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u2-20020a0ca702000000b0067f91ebcd11si2653791qva.520.2024.01.09.10.41.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 10:41:19 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=ZAM3WLN7; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E010A385E038 for ; Tue, 9 Jan 2024 17:21:44 +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 0C3F4385829C for ; Tue, 9 Jan 2024 17:20:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0C3F4385829C 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 0C3F4385829C 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=1704820860; cv=none; b=TCH1pNTO+LXZ2SDqz5cg+tPa8Tt23J0+1Un0DrNoYuMQBezMYJoHMS6N/wjhCf/0GqJfT9b+ZQTpUpZXU8U8cgkphuVh9brXSugITfIrGKGbQeBeezbwMTEBjQBKhSXcLXP3HusPa6aEU3jMTX8gj7j1aWp/jtGmf4ogtoyZ1ac= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704820860; c=relaxed/simple; bh=fDBtGhU1jI3SLd7Via7Ne9rHz3PnHDtXKv0eG7mwdbw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=q7P23viW2ixVMcOyqzhPZkgg35hRBdWy3DM+T1de1y+CV72EJ98GepwcUucm34LdRMZtV4VKz6UnKUJlkrOio3GRxasgvHlIspzStUpCgdAtFRstxYlxjMbU3EhKVgfqjVZpw2imueg9of3ucv886L0AtnQxlo3tbP4jjd5Cupc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704820857; 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=mgNkoD57GSGHy8L6mQc/pBvruLkSKBv0+XXBu2u4JcU=; b=ZAM3WLN7ZTqb8EtmMZXOxV/fK5KCW4W8icSDQpvSzA+L1uHwrxNrpCtXmrIHr128396q+j rj3vD+YxjsX2NcDEpS5xzOmEoqDW5gyqTDeqS8KBFhAnAOQqo9a3uIwUv3noHeqaeIz+8U ps6g9WZn/lwB4nJpTCznkyhoR1KosQU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-ODxRGPikO2mODsFOzNvSGQ-1; Tue, 09 Jan 2024 12:20:56 -0500 X-MC-Unique: ODxRGPikO2mODsFOzNvSGQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD21D1C16E4A; Tue, 9 Jan 2024 17:20:55 +0000 (UTC) Received: from localhost (unknown [10.42.28.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6AC41C060AF; Tue, 9 Jan 2024 17:20:55 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Simplify some chrono formatters Date: Tue, 9 Jan 2024 17:20:39 +0000 Message-ID: <20240109172054.3968493-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 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_H3, RCVD_IN_MSPIKE_WL, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787639291881362853 X-GMAIL-MSGID: 1787639291881362853 Tested aarch64-linux. Pushed to trunk. -- >8 -- I don't remember exactly why I made these bits of code reserve space in a COW string and append to it, rather than just use the string returned from std::format (which will undergo copy elision). The _Str_sink type used by std::format means the string only performs a single allocation for the formatted output, and the returned string's reference count will be one, so won't reallocate when indexing into it. We can remove these non-optimizations. libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_F): Simplify handling of string returned from std::format. (__formatter_chrono::_M_R_T): Likewise. --- libstdc++-v3/include/bits/chrono_io.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index ec2ae9d53cc..7b5876b24e6 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -898,11 +898,8 @@ namespace __format _FormatContext&) const { auto __ymd = _S_date(__t); - basic_string<_CharT> __s; -#if ! _GLIBCXX_USE_CXX11_ABI - __s.reserve(11); -#endif - __s += std::format(_GLIBCXX_WIDEN("{:04d}- - "), (int)__ymd.year()); + auto __s = std::format(_GLIBCXX_WIDEN("{:04d}- - "), + (int)__ymd.year()); auto __sv = _S_two_digits((unsigned)__ymd.month()); __s[__s.size() - 5] = __sv[0]; __s[__s.size() - 4] = __sv[1]; @@ -1093,11 +1090,8 @@ namespace __format // %T Equivalent to %H:%M:%S auto __hms = _S_hms(__t); - basic_string<_CharT> __s; -#if ! _GLIBCXX_USE_CXX11_ABI - __s.reserve(11); -#endif - __s = std::format(_GLIBCXX_WIDEN("{:02d}:00"), __hms.hours().count()); + auto __s = std::format(_GLIBCXX_WIDEN("{:02d}:00"), + __hms.hours().count()); auto __sv = _S_two_digits(__hms.minutes().count()); __s[__s.size() - 2] = __sv[0]; __s[__s.size() - 1] = __sv[1];