[Libreoffice-commits] core.git: sc/source

Eike Rathke erack at redhat.com
Tue Sep 20 19:52:25 UTC 2016


 sc/source/core/tool/compiler.cxx |   48 +++++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 4 deletions(-)

New commits:
commit 73c7e0921d752df53004ed55735f3e8888cc592f
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Sep 20 21:39:10 2016 +0200

    sc-perf: tdf#79023 for ODFF do not call SvNumberFormatter to determine numeric
    
    Speedup of this particular function and callees by factor 33 ...
    
    1000 calls for =12345.6789 and =123.456 alternating:
    
    Before:
    Ir       Irpc  Callee
    9859177  9859  ScCompiler::IsValue
    6246858  6246  SvNumberFormatter::IsNumberFormat
    3496261  3496  SvNumberFormatter::GetStandardIndex
    
    After:
     298000   298  ScCompiler::IsValue
     248000   248  rtl_math_uStringToDouble
    
    Change-Id: I36eac8c5fe1b1cbf34dfb480c9e7ca6607769364

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 921ee97..e620032 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -2885,8 +2885,51 @@ bool ScCompiler::IsOpCode2( const OUString& rName )
     return bFound;
 }
 
+static bool lcl_ParenthesisFollows( const sal_Unicode* p )
+{
+    while (*p == ' ')
+        p++;
+    return *p == '(';
+}
+
 bool ScCompiler::IsValue( const OUString& rSym )
 {
+    if (FormulaGrammar::isODFF( GetGrammar()))
+    {
+        // Speedup things for ODFF, only well-formed numbers, not locale
+        // dependent nor user input.
+        rtl_math_ConversionStatus eStatus;
+        sal_Int32 nParseEnd;
+        double fVal = rtl::math::stringToDouble( rSym, '.', 0, &eStatus, &nParseEnd);
+        if (nParseEnd != rSym.getLength())
+        {
+            // Not (only) a number.
+
+            if (nParseEnd > 0)
+                return false;   // partially a number => no such thing
+
+            if (lcl_ParenthesisFollows( aFormula.getStr() + nSrcPos))
+                return false;   // some function name, not a constant
+
+            // Could be TRUE or FALSE constant.
+            if (rSym.equalsIgnoreAsciiCase("TRUE"))
+            {
+                maRawToken.SetDouble( 1.0 );
+                return true;
+            }
+            if (rSym.equalsIgnoreAsciiCase("FALSE"))
+            {
+                maRawToken.SetDouble( 0.0 );
+                return true;
+            }
+            return false;
+        }
+        if (eStatus == rtl_math_ConversionStatus_OutOfRange)
+            SetError( errIllegalArgument );
+        maRawToken.SetDouble( fVal );
+        return true;
+    }
+
     double fVal;
     sal_uInt32 nIndex = mxSymbols->isEnglish() ? mpFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US) : 0;
 
@@ -2905,10 +2948,7 @@ bool ScCompiler::IsValue( const OUString& rSym )
 
     if (nType == css::util::NumberFormat::LOGICAL)
     {
-        const sal_Unicode* p = aFormula.getStr() + nSrcPos;
-        while( *p == ' ' )
-            p++;
-        if (*p == '(')
+        if (lcl_ParenthesisFollows( aFormula.getStr() + nSrcPos))
             return false;   // Boolean function instead.
     }
 


More information about the Libreoffice-commits mailing list