aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-09-07 20:09:17 +0100
committerJonathan Wakely <jwakely@redhat.com>2020-09-07 20:09:17 +0100
commitec5096f48bbd7db83cbe94bdd3235c5808a5979a (patch)
tree479c47fbcac92b549d89601497e22148a71783f9
parent00ffe730072f5e2e1923692163dc37db7b3784cb (diff)
downloadgcc-ec5096f48bbd7db83cbe94bdd3235c5808a5979a.zip
gcc-ec5096f48bbd7db83cbe94bdd3235c5808a5979a.tar.gz
gcc-ec5096f48bbd7db83cbe94bdd3235c5808a5979a.tar.bz2
libstdc++: Simplify chrono::duration::_S_gcd
We can simplify this constexpr function further because we know that period::num >= 1 and period::den >= 1 so only the remainder can ever be zero. libstdc++-v3/ChangeLog: * include/std/chrono (duration::_S_gcd): Use invariant that neither value is zero initially.
-rw-r--r--libstdc++-v3/include/std/chrono7
1 files changed, 4 insertions, 3 deletions
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index 0e2efb2..afee785 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -430,17 +430,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Duration only allows positive periods so we don't need to
// handle negative values here (unlike __static_gcd and std::gcd).
#if __cplusplus >= 201402L
- while (__m != 0 && __n != 0)
+ do
{
intmax_t __rem = __m % __n;
__m = __n;
__n = __rem;
}
- return __m + __n;
+ while (__n != 0);
+ return __m;
#else
// C++11 doesn't allow loops in constexpr functions, but this
// recursive version can be more expensive to evaluate.
- return (__m == 0) ? __n : (__n == 0) ? __m : _S_gcd(__n, __m % __n);
+ return (__n == 0) ? __m : _S_gcd(__n, __m % __n);
#endif
}