[Libreoffice-commits] core.git: include/o3tl

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Thu Feb 25 16:23:39 UTC 2021


 include/o3tl/unit_conversion.hxx |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

New commits:
commit 27dd792d6db7012e3e819615e6ee937e2990beec
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu Feb 25 10:41:45 2021 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu Feb 25 17:22:59 2021 +0100

    Use std::gcd
    
    Change-Id: Ie24472aa2fd3bcda0ccb5945de38bd865b7d01aa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111462
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index f377b16e8b10..434f2e50c1c8 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -15,6 +15,7 @@
 
 #include <array>
 #include <cassert>
+#include <numeric>
 #include <utility>
 #include <type_traits>
 
@@ -106,17 +107,14 @@ constexpr sal_Int64 MulDivSaturate(I n, sal_Int64 m, sal_Int64 d)
     return MulDiv(n, m, d);
 }
 
-// Greatest common divisor
-constexpr int gcd(sal_Int64 a, sal_Int64 b) { return b == 0 ? a : gcd(b, a % b); }
-
 // Packs integral multiplier and divisor for conversion from one unit to another
 struct m_and_d
 {
     sal_Int64 m; // multiplier
     sal_Int64 d; // divisor
     constexpr m_and_d(sal_Int64 _m, sal_Int64 _d)
-        : m(_m / gcd(_m, _d)) // make sure to use smallest quotients here because
-        , d(_d / gcd(_m, _d)) // they will be multiplied when building final table
+        : m(_m / std::gcd(_m, _d)) // make sure to use smallest quotients here because
+        , d(_d / std::gcd(_m, _d)) // they will be multiplied when building final table
     {
         assert(_m > 0 && _d > 0);
     }
@@ -139,7 +137,7 @@ template <int N> constexpr auto prepareMDArray(const m_and_d (&mdBase)[N])
                 assert(mdBase[i].m < SAL_MAX_INT64 / mdBase[j].d);
                 assert(mdBase[i].d < SAL_MAX_INT64 / mdBase[j].m);
                 const sal_Int64 m = mdBase[i].m * mdBase[j].d, d = mdBase[i].d * mdBase[j].m;
-                const sal_Int64 g = gcd(m, d);
+                const sal_Int64 g = std::gcd(m, d);
                 a[i][j] = m / g;
                 a[j][i] = d / g;
             }


More information about the Libreoffice-commits mailing list