summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-09-03 17:43:29 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-09-04 06:18:06 +0200
commitfef0256122442a6536601f28914c516b036f7935 (patch)
treeb680a1c3abc016160de4db48a79c1da15390d525 /connectivity
parent677750f3f3d21c40e37cc4296673c931a0cb3779 (diff)
Optimize taking powers of 10, and move to the only place it's used
Change-Id: I78b1ecb037f84ba4e7894d2a5ab088b7acb3f210 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172802 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/firebird/PreparedStatement.cxx29
-rw-r--r--connectivity/source/drivers/firebird/Util.cxx11
-rw-r--r--connectivity/source/drivers/firebird/Util.hxx2
3 files changed, 28 insertions, 14 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index f13b06be5c83..9fb70c305adb 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -356,6 +356,33 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery()
namespace {
+sal_Int64 toPowOf10AndRound(double n, int powOf10)
+{
+ constexpr sal_Int64 powers[] = {
+ 1,
+ 10,
+ 100,
+ 1000,
+ 10000,
+ 100000,
+ 1000000,
+ 10000000,
+ 100000000,
+ 1000000000,
+ 10000000000,
+ 100000000000,
+ 1000000000000,
+ 10000000000000,
+ 100000000000000,
+ 1000000000000000,
+ 10000000000000000,
+ 100000000000000000,
+ 1000000000000000000,
+ };
+ powOf10 = std::clamp(powOf10, 0, int(std::size(powers) - 1));
+ return n * powers[powOf10] + (n >= 0 ? 0.5 : -0.5);
+}
+
/**
* Take out the number part of a fix point decimal without
* the information of where is the fractional part from a
@@ -364,7 +391,7 @@ namespace {
sal_Int64 toNumericWithoutDecimalPlace(const Any& x, sal_Int32 scale)
{
if (double value = 0; x >>= value)
- return static_cast<sal_Int64>(value * pow10Integer(scale) + (value >= 0 ? 0.5 : -0.5));
+ return toPowOf10AndRound(value, scale);
// Can't use conversion of string to double, because it could be not representable in double
diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx
index d2ac59d628ad..6d0153fdfe0b 100644
--- a/connectivity/source/drivers/firebird/Util.cxx
+++ b/connectivity/source/drivers/firebird/Util.cxx
@@ -410,15 +410,4 @@ void firebird::freeSQLVAR(XSQLDA* pSqlda)
}
}
-
-sal_Int64 firebird::pow10Integer(int nDecimalCount)
-{
- sal_Int64 nRet = 1;
- for(int i=0; i< nDecimalCount; i++)
- {
- nRet *= 10;
- }
- return nRet;
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/connectivity/source/drivers/firebird/Util.hxx b/connectivity/source/drivers/firebird/Util.hxx
index 3e0e806bd5de..62ba0e2f9640 100644
--- a/connectivity/source/drivers/firebird/Util.hxx
+++ b/connectivity/source/drivers/firebird/Util.hxx
@@ -118,8 +118,6 @@ public:
void freeSQLVAR(XSQLDA* pSqlda);
- sal_Int64 pow10Integer( int nDecimalCount );
-
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */