public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-7072] libstdc++: Simplify some chrono formatters Date: Tue, 9 Jan 2024 17:20:39 +0000 (GMT) [thread overview] Message-ID: <20240109172039.1EF7238582A2@sourceware.org> (raw) https://gcc.gnu.org/g:8ae50799cd25a63fa028eb6aad4f93be1d8eeb39 commit r14-7072-g8ae50799cd25a63fa028eb6aad4f93be1d8eeb39 Author: Jonathan Wakely <jwakely@redhat.com> Date: Thu Dec 14 15:29:13 2023 +0000 libstdc++: Simplify some chrono formatters 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. Diff: --- 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];
reply other threads:[~2024-01-09 17:20 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240109172039.1EF7238582A2@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).