svl/source/numbers/zforfind.cxx |   30 ++++--------------------------
 svl/source/numbers/zforfind.hxx |    8 --------
 2 files changed, 4 insertions(+), 34 deletions(-)

New commits:
commit eab77eea7fe93bec66bf6996fd4db2da0725073c
Author:     Mike Kaganski <[email protected]>
AuthorDate: Sun Sep 21 16:26:43 2025 +0500
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Oct 3 08:22:58 2025 +0200

    Simplify and speed up ImpSvNumberInputScan::StringToDouble
    
    ... and make it a local static, instead of static class member. It
    is only used in this unit, so no need to have it in the class.
    
    The removed bForceFraction argument was only used in one place (for
    fractions of a second in GetTimeRef); the old implementation copied
    the string into an internal buffer before passing to from_chars; it
    was only needed to insert a dot for bForceFraction case.
    
    Removing bForceFraction, and directly passing aStr to from_chars,
    which accepts char16_t-based strings as well, improves performance
    for all other uses of StringToDouble. In GetTimeRef, we now prepend
    the decimal point explicitly.
    
    Change-Id: I5973eee8108c97d758d4207be2a47aef4f5f98b7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191288
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    (cherry picked from commit 634c512c90891dfb8dd98b80aebb5b1d9d245681)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191303
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx
index df8308b69f1f..12f27584b1ed 100644
--- a/svl/source/numbers/zforfind.cxx
+++ b/svl/source/numbers/zforfind.cxx
@@ -151,33 +151,11 @@ static void TransformInput(const NativeNumberWrapper& 
rNatNum, const SvNFLanguag
  * Only simple unsigned floating point values without any error detection,
  * decimal separator has to be '.'
  */
-double ImpSvNumberInputScan::StringToDouble( std::u16string_view aStr, bool 
bForceFraction )
+static double StringToDouble( std::u16string_view aStr )
 {
-    std::unique_ptr<char[]> bufInHeap;
-    constexpr int bufOnStackSize = 256;
-    char bufOnStack[bufOnStackSize];
-    char* buf = bufOnStack;
-    const sal_Int32 bufsize = aStr.size() + (bForceFraction ? 2 : 1);
-    if (bufsize > bufOnStackSize)
-    {
-        bufInHeap = std::make_unique<char[]>(bufsize);
-        buf = bufInHeap.get();
-    }
-    char* p = buf;
-    if (bForceFraction)
-        *p++ = '.';
-    for (size_t nPos = 0; nPos < aStr.size(); ++nPos)
-    {
-        sal_Unicode c = aStr[nPos];
-        if (c == '.' || (c >= '0' && c <= '9'))
-            *p++ = static_cast<char>(c);
-        else
-            break;
-    }
-
+    const auto fmt = fast_float::chars_format::fixed | 
fast_float::chars_format::no_infnan;
     double result = 0;
-    (void)fast_float::from_chars(
-        buf, p, result, fast_float::chars_format::fixed | 
fast_float::chars_format::no_infnan);
+    (void)fast_float::from_chars(aStr.data(), aStr.data() + aStr.size(), 
result, fmt);
     return result;
 }
 
@@ -1056,7 +1034,7 @@ bool ImpSvNumberInputScan::GetTimeRef( double& fOutNumber,
     }
     if (nIndex - nStartIndex < nCnt)
     {
-        fSecond100 = StringToDouble( sStrArray[nNums[nIndex]], true );
+        fSecond100 = StringToDouble(Concat2View("." + 
sStrArray[nNums[nIndex]]));
     }
     fOutNumber = (static_cast<double>(nHour)*3600 +
                   static_cast<double>(nMinute)*60 +
diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx
index 8765697cb5f9..98eba858a4a5 100644
--- a/svl/source/numbers/zforfind.hxx
+++ b/svl/source/numbers/zforfind.hxx
@@ -190,14 +190,6 @@ private:
 
     void InitText();                            // Init of months and days of 
week
 
-    // Convert string to double.
-    // Only simple unsigned floating point values without any error detection,
-    // decimal separator has to be '.'
-    // If bForceFraction==true the string is taken to be the fractional part
-    // of 0.1234 without the leading 0. (thus being just "1234").
-    static double StringToDouble( std::u16string_view aStr,
-                                  bool bForceFraction = false );
-
     // Next number/string symbol
     static bool NextNumberStringSymbol( const sal_Unicode*& pStr,
                                         OUString& rSymbol );

Reply via email to