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 r11-3040] libstdc++: Simplify chrono::duration::_S_gcd
Date: Mon,  7 Sep 2020 19:12:22 +0000 (GMT)	[thread overview]
Message-ID: <20200907191222.5244F386186A@sourceware.org> (raw)

https://gcc.gnu.org/g:ec5096f48bbd7db83cbe94bdd3235c5808a5979a

commit r11-3040-gec5096f48bbd7db83cbe94bdd3235c5808a5979a
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Sep 7 20:09:17 2020 +0100

    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.

Diff:
---
 libstdc++-v3/include/std/chrono | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index 0e2efb2522b..afee7859c6d 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
 	}


                 reply	other threads:[~2020-09-07 19:12 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=20200907191222.5244F386186A@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: link
Be 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).