connectivity/source/drivers/firebird/PreparedStatement.cxx |   29 ++++++++++++-
 connectivity/source/drivers/firebird/Util.cxx              |   11 ----
 connectivity/source/drivers/firebird/Util.hxx              |    2 
 3 files changed, 28 insertions(+), 14 deletions(-)

New commits:
commit fef0256122442a6536601f28914c516b036f7935
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Tue Sep 3 17:43:29 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Sep 4 06:18:06 2024 +0200

    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.kagan...@collabora.com>

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: */

Reply via email to