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 r12-4383] libstdc++: Fix regression in memory use when constructing paths Date: Wed, 13 Oct 2021 22:48:48 +0000 (GMT) [thread overview] Message-ID: <20211013224848.1DA1F385840B@sourceware.org> (raw) https://gcc.gnu.org/g:f874a13ca3870a56036a90758b0d41c8c217f4f7 commit r12-4383-gf874a13ca3870a56036a90758b0d41c8c217f4f7 Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Oct 13 21:32:14 2021 +0100 libstdc++: Fix regression in memory use when constructing paths The changes in r12-4381 were intended to reduce memory usage, but replacing the __contiguous constant in __string_from_range with the new __is_contiguous variable template caused a regression. The old code checked is_pointer_v<decltype(std::__niter_base(__first))> but he new code just checks is_pointer_v<_InputIterator>. This means that we no longer recognise basic_string::iterator and vector::iterator as contiguous, and so return a temporary basic_string instead of a basic_string_view. This only affects C++17 mode, because the std::contiguous_iterator concept is used in C++20 which gives the right answer for __normal_iterator (and more types as well). The fix is to specialize the new __is_contiguous variable template so it is true for __normal_iterator<T*, C> specializations. The new partial specializations are defined for C++20 too, because it should be cheaper to match the partial specialization than to check whether the std::contiguous_iterator concept is satisfied. libstdc++-v3/ChangeLog: * include/bits/fs_path.h (__detail::__is_contiguous): Add partial specializations for pointers and __normal_iterator. Diff: --- libstdc++-v3/include/bits/fs_path.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 05db792fbae..c51bfa3095a 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -158,9 +158,16 @@ namespace __detail constexpr bool __is_contiguous = std::contiguous_iterator<_Iter>; #else template<typename _Iter> - constexpr bool __is_contiguous = is_pointer_v<_Iter>; + constexpr bool __is_contiguous = false; #endif + template<typename _Tp> + constexpr bool __is_contiguous<_Tp*> = true; + + template<typename _Tp, typename _Seq> + constexpr bool + __is_contiguous<__gnu_cxx::__normal_iterator<_Tp*, _Seq>> = true; + #if !defined _GLIBCXX_FILESYSTEM_IS_WINDOWS && defined _GLIBCXX_USE_CHAR8_T // For POSIX treat char8_t sequences as char without encoding conversions. template<typename _EcharT>
reply other threads:[~2021-10-13 22:48 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=20211013224848.1DA1F385840B@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).