* [PATCH] libstdc++: Move code after an early exit constexpr if to under an else branch
@ 2020-02-15 16:29 Patrick Palka
2020-02-15 20:01 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2020-02-15 16:29 UTC (permalink / raw)
To: gcc-patches; +Cc: libstdc++, jwakely, Patrick Palka
This avoids instantiating dead code when the true branch of the constexpr if is
taken.
[ diffstat generated with -w to ignore noisy whitespace changes ]
libstdc++-v3/ChangeLog:
* include/bits/ranges_algo.h (__lexicographical_compare_fn::operator()):
Move code after an early exit constexpr if to under an else branch.
* include/bits/ranges_algobase.h (__equal_fn::operator()): Likewise.
---
libstdc++-v3/include/bits/ranges_algo.h | 7 +++++--
libstdc++-v3/include/bits/ranges_algobase.h | 7 ++-----
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/libstdc++-v3/include/bits/ranges_algo.h b/libstdc++-v3/include/bits/ranges_algo.h
index 7f8f0fb964b..ff1b40f6ace 100644
--- a/libstdc++-v3/include/bits/ranges_algo.h
+++ b/libstdc++-v3/include/bits/ranges_algo.h
@@ -3318,7 +3318,8 @@ namespace ranges
std::__niter_base(std::move(__last2)),
std::move(__comp),
std::move(__proj1), std::move(__proj2));
-
+ else
+ {
constexpr bool __sized_iters
= (sized_sentinel_for<_Sent1, _Iter1>
&& sized_sentinel_for<_Sent2, _Iter2>);
@@ -3342,7 +3343,8 @@ namespace ranges
{
if (const auto __len = std::min(__d1, __d2))
{
- const auto __c = std::__memcmp(__first1, __first2, __len);
+ const auto __c
+ = std::__memcmp(__first1, __first2, __len);
if constexpr (is_same_v<_Comp, ranges::less>)
{
if (__c < 0)
@@ -3378,6 +3380,7 @@ namespace ranges
}
return __first1 == __last1 && __first2 != __last2;
}
+ }
template<input_range _Range1, input_range _Range2,
typename _Proj1 = identity, typename _Proj2 = identity,
diff --git a/libstdc++-v3/include/bits/ranges_algobase.h b/libstdc++-v3/include/bits/ranges_algobase.h
index f8643b5a933..cc24483b2d3 100644
--- a/libstdc++-v3/include/bits/ranges_algobase.h
+++ b/libstdc++-v3/include/bits/ranges_algobase.h
@@ -93,11 +93,8 @@ namespace ranges
std::__niter_base(std::move(__last2)),
std::move(__pred),
std::move(__proj1), std::move(__proj2));
-
- constexpr bool __sized_iters
- = (sized_sentinel_for<_Sent1, _Iter1>
- && sized_sentinel_for<_Sent2, _Iter2>);
- if constexpr (__sized_iters)
+ else if constexpr (sized_sentinel_for<_Sent1, _Iter1>
+ && sized_sentinel_for<_Sent2, _Iter2>)
{
auto __d1 = ranges::distance(__first1, __last1);
auto __d2 = ranges::distance(__first2, __last2);
--
2.25.0.232.gd8437c57fa
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] libstdc++: Move code after an early exit constexpr if to under an else branch
2020-02-15 16:29 [PATCH] libstdc++: Move code after an early exit constexpr if to under an else branch Patrick Palka
@ 2020-02-15 20:01 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2020-02-15 20:01 UTC (permalink / raw)
To: Patrick Palka; +Cc: gcc-patches, libstdc++
On 15/02/20 11:28 -0500, Patrick Palka wrote:
>This avoids instantiating dead code when the true branch of the constexpr if is
>taken.
>
>[ diffstat generated with -w to ignore noisy whitespace changes ]
>
>libstdc++-v3/ChangeLog:
>
> * include/bits/ranges_algo.h (__lexicographical_compare_fn::operator()):
> Move code after an early exit constexpr if to under an else branch.
> * include/bits/ranges_algobase.h (__equal_fn::operator()): Likewise.
OK for master, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-15 20:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-15 16:29 [PATCH] libstdc++: Move code after an early exit constexpr if to under an else branch Patrick Palka
2020-02-15 20:01 ` Jonathan Wakely
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).