summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-03-30 09:02:12 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2021-03-30 10:11:45 +0200
commit852c4f8cded79435bd69675e9e9a10034b385219 (patch)
treed4e4f9f561af1e6b07c8055b862f5f5c97e6dd4c
parent2e8d635f7908497898c2d90b45070a3467fd15a5 (diff)
Simplify prepareMDArray
Change-Id: I1b8c0dead67b48c25ddcc02e83c3305cf93ebd5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113288 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--include/o3tl/unit_conversion.hxx20
1 files changed, 8 insertions, 12 deletions
diff --git a/include/o3tl/unit_conversion.hxx b/include/o3tl/unit_conversion.hxx
index 434f2e50c1c8..4c76375737a2 100644
--- a/include/o3tl/unit_conversion.hxx
+++ b/include/o3tl/unit_conversion.hxx
@@ -128,19 +128,15 @@ template <int N> constexpr auto prepareMDArray(const m_and_d (&mdBase)[N])
std::array<std::array<sal_Int64, N>, N> a{};
for (int i = 0; i < N; ++i)
{
- for (int j = 0; j <= i; ++j)
+ a[i][i] = 1;
+ for (int j = 0; j < i; ++j)
{
- if (i == j)
- a[i][j] = 1;
- else
- {
- 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 = std::gcd(m, d);
- a[i][j] = m / g;
- a[j][i] = d / g;
- }
+ 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 = std::gcd(m, d);
+ a[i][j] = m / g;
+ a[j][i] = d / g;
}
}
return a;