From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 985E73858D37 for ; Fri, 1 Sep 2023 10:55:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 985E73858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693565716; 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=HR2OD/kzTVc1l8PqDxChIwREiz+DwWjJmVhtxR0XT68=; b=f4oQWglzseuzH+62egJmsxKIImSFM5CvBEoLVmKuWXUDAjagTGcOP867f8+VbT7yw6M42U O6PjtuVKp2CNM3KIl95fotS+7q7GV9DaAaVa/JCL4hjO7tB/7/rrhZjh1n6i7mJPliSu4+ Zrm51C8z9TZXBklKW0iTbeAKNvIyziA= Received: from mimecast-mx02.redhat.com (mx-ext.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-113-dvilpk-cPVaLfxlvyd0I0A-1; Fri, 01 Sep 2023 06:55:15 -0400 X-MC-Unique: dvilpk-cPVaLfxlvyd0I0A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C2AED1C170D2; Fri, 1 Sep 2023 10:55:14 +0000 (UTC) Received: from localhost (unknown [10.42.28.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AA5B493112; Fri, 1 Sep 2023 10:55:14 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Simplify __format::_Sink::_M_reset Date: Fri, 1 Sep 2023 11:55:00 +0100 Message-ID: <20230901105513.226352-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit 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 List-Id: Tested x86_64-linux. Pushed to trunk. -- >8 -- Using an offset as the second argument instead of an iterator makes it easier for callers, as they don't need to create an lvalue span in order to get an iterator from it for the _M_reset call. libstdc++-v3/ChangeLog: * include/std/format (__format::_Sink::_M_reset): Change second argument from iterator to offset. --- libstdc++-v3/include/std/format | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format index fe2caa58688..128a5b79282 100644 --- a/libstdc++-v3/include/std/format +++ b/libstdc++-v3/include/std/format @@ -2537,11 +2537,10 @@ namespace __format // Replace the current output range. void - _M_reset(span<_CharT> __s, - typename span<_CharT>::iterator __next) noexcept + _M_reset(span<_CharT> __s, size_t __pos = 0) noexcept { _M_span = __s; - _M_next = __next; + _M_next = __s.begin() + __pos; } // Called by the iterator for *it++ = c @@ -2599,7 +2598,7 @@ namespace __format // A sink that fills a sequence (e.g. std::string, std::vector, std::deque). // Writes to a buffer then appends that to the sequence when it fills up. template - class _Seq_sink : public _Buf_sink + class _Seq_sink final : public _Buf_sink { using _CharT = typename _Seq::value_type; @@ -2610,6 +2609,8 @@ namespace __format _M_overflow() override { auto __s = this->_M_used(); + if (__s.empty()) + return; if constexpr (__is_specialization_of<_Seq, basic_string>) _M_seq.append(__s.data(), __s.size()); else @@ -2618,6 +2619,9 @@ namespace __format } public: + // TODO: for SSO string, use SSO buffer as initial span, then switch + // to _M_buf if it overflows? Or even do that for all unused capacity? + [[__gnu__::__always_inline__]] _Seq_sink() noexcept(is_nothrow_default_constructible_v<_Seq>) { } @@ -2722,21 +2726,20 @@ namespace __format return; // No need to switch to internal buffer yet. auto __s = this->_M_used(); - _M_count += __s.size(); if (_M_max >= 0) { + _M_count += __s.size(); // Span was already sized for the maximum character count, // if it overflows then any further output must go to the // internal buffer, to be discarded. - span<_CharT> __buf{_M_buf}; - this->_M_reset(__buf, __buf.begin()); + this->_M_reset(this->_M_buf); } else { // No maximum character count. Just extend the span to allow // writing more characters to it. - this->_M_reset({__s.data(), __s.size() + 1024}, __s.end()); + this->_M_reset({__s.data(), __s.size() + 1024}, __s.size()); } } @@ -3473,6 +3476,7 @@ namespace __format template template + inline basic_format_args<_Context>:: basic_format_args(const _Store<_Args...>& __store) noexcept { @@ -4063,7 +4067,7 @@ namespace __format { #if 1 template - class _Counting_sink : public _Iter_sink<_CharT, _CharT*> + class _Counting_sink final : public _Iter_sink<_CharT, _CharT*> { public: _Counting_sink() : _Iter_sink<_CharT, _CharT*>(nullptr, 0) { } -- 2.41.0