public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-3062] libstdc++: Avoid heavyweight std::visit in ranges::join_with_view Date: Tue, 4 Oct 2022 14:54:44 +0000 (GMT) [thread overview] Message-ID: <20221004145444.292653858CDA@sourceware.org> (raw) https://gcc.gnu.org/g:3b8bcc3f8b821e7359f8504334488ff2b1fc8f30 commit r13-3062-g3b8bcc3f8b821e7359f8504334488ff2b1fc8f30 Author: Patrick Palka <ppalka@redhat.com> Date: Tue Oct 4 10:54:36 2022 -0400 libstdc++: Avoid heavyweight std::visit in ranges::join_with_view libstdc++-v3/ChangeLog: * include/std/ranges (join_with_view::_Iterator::operator*): Replace use of std::visit with manual visitation. (join_with_view::_Iterator::operator++): Likewise. (join_with_view::_Iterator::operator--): Likewise. (join_with_view::_Iterator::iter_move): Likewise. (join_with_view::_Iterator::iter_swap): Likewise. Diff: --- libstdc++-v3/include/std/ranges | 47 +++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index d0d6ce61a87..1f821128d2d 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -7165,18 +7165,23 @@ namespace views::__adaptor _M_inner_it.template emplace<1>(std::get<1>(std::move(__i._M_inner_it))); } - constexpr decltype(auto) + constexpr common_reference_t<iter_reference_t<_InnerIter>, + iter_reference_t<_PatternIter>> operator*() const { - using reference = common_reference_t<iter_reference_t<_InnerIter>, - iter_reference_t<_PatternIter>>; - return std::visit([](auto& __it) -> reference { return *__it; }, _M_inner_it); + if (_M_inner_it.index() == 0) + return *std::get<0>(_M_inner_it); + else + return *std::get<1>(_M_inner_it); } constexpr _Iterator& operator++() { - std::visit([](auto& __it){ ++__it; }, _M_inner_it); + if (_M_inner_it.index() == 0) + ++std::get<0>(_M_inner_it); + else + ++std::get<1>(_M_inner_it); _M_satisfy(); return *this; } @@ -7232,7 +7237,10 @@ namespace views::__adaptor } } - std::visit([](auto& __it){ --__it; }, _M_inner_it); + if (_M_inner_it.index() == 0) + --std::get<0>(_M_inner_it); + else + --std::get<1>(_M_inner_it); return *this; } @@ -7253,18 +7261,35 @@ namespace views::__adaptor && equality_comparable<_OuterIter> && equality_comparable<_InnerIter> { return __x._M_outer_it == __y._M_outer_it && __x._M_inner_it ==__y._M_inner_it; } - friend constexpr decltype(auto) + friend constexpr common_reference_t<iter_rvalue_reference_t<_InnerIter>, + iter_rvalue_reference_t<_PatternIter>> iter_move(const _Iterator& __x) { - using __rval_ref = common_reference_t<iter_rvalue_reference_t<_InnerIter>, - iter_rvalue_reference_t<_PatternIter>>; - return std::visit<__rval_ref>(ranges::iter_move, __x._M_inner_it); + if (__x._M_inner_it.index() == 0) + return ranges::iter_move(std::get<0>(__x._M_inner_it)); + else + return ranges::iter_move(std::get<1>(__x._M_inner_it)); } friend constexpr void iter_swap(const _Iterator& __x, const _Iterator& __y) requires indirectly_swappable<_InnerIter, _PatternIter> - { std::visit(ranges::iter_swap, __x._M_inner_it, __y._M_inner_it); } + { + if (__x._M_inner_it.index() == 0) + { + if (__y._M_inner_it.index() == 0) + ranges::iter_swap(std::get<0>(__x._M_inner_it), std::get<0>(__y._M_inner_it)); + else + ranges::iter_swap(std::get<0>(__x._M_inner_it), std::get<1>(__y._M_inner_it)); + } + else + { + if (__y._M_inner_it.index() == 0) + ranges::iter_swap(std::get<1>(__x._M_inner_it), std::get<0>(__y._M_inner_it)); + else + ranges::iter_swap(std::get<1>(__x._M_inner_it), std::get<1>(__y._M_inner_it)); + } + } }; template<input_range _Vp, forward_range _Pattern>
reply other threads:[~2022-10-04 14:54 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=20221004145444.292653858CDA@sourceware.org \ --to=ppalka@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).