sc/inc/compiler.hxx              |    6 ++----
 sc/source/core/tool/compiler.cxx |    4 ++--
 sc/source/core/tool/token.cxx    |   32 +++++++++-----------------------
 3 files changed, 13 insertions(+), 29 deletions(-)

New commits:
commit fc79121c95d111d519e58478b48957d2d4f8612d
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Aug 3 21:44:19 2018 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Aug 6 11:45:48 2018 +0200

    skip some copying with external names in ScRawToken
    
    No need to convert from an OUString to a sal_Unicode[] and then back
    again.
    There is only one ScRawToken allocated so no need to be ultra careful
    with extra fields here.
    
    Change-Id: I279835e83ba02d9d4cf4d724bd8046be6aca1405
    Reviewed-on: https://gerrit.libreoffice.org/58580
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index 17e87347a23d..969bd41d838a 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -114,12 +114,10 @@ public:
         ScComplexRefData aRef;
         struct {
             sal_uInt16          nFileId;
-            sal_Unicode         cTabName[MAXSTRLEN+1];
             ScComplexRefData    aRef;
         } extref;
         struct {
             sal_uInt16  nFileId;
-            sal_Unicode cName[MAXSTRLEN+1];
         } extname;
         struct {
             sal_Int16   nSheet;
@@ -135,9 +133,9 @@ public:
         } sharedstring;
         ScMatrix*    pMat;
         FormulaError nError;
-        sal_Unicode  cStr[ 1+MAXSTRLEN+1 ];   // string (byteparam + up to 
MAXSTRLEN characters + 0)
         short        nJump[ FORMULA_MAXJUMPCOUNT + 1 ];     // If/Chose token
     };
+    OUString   maExternalName; // depending on the opcode, this is either the 
external, or the external name, or the external table name
 
     // coverity[uninit_member] - members deliberately not initialized
     ScRawToken() {}
@@ -163,7 +161,7 @@ public:
     void SetExternalSingleRef( sal_uInt16 nFileId, const OUString& rTabName, 
const ScSingleRefData& rRef );
     void SetExternalDoubleRef( sal_uInt16 nFileId, const OUString& rTabName, 
const ScComplexRefData& rRef );
     void SetExternalName( sal_uInt16 nFileId, const OUString& rName );
-    void SetExternal(const sal_Unicode* pStr);
+    void SetExternal(const OUString& rStr);
 
     /** If the token is a non-external reference, determine if the reference is
         valid. If the token is an external reference, return true. Else return
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 54e816b5ff7a..831f8ec677f1 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -2883,7 +2883,7 @@ bool ScCompiler::IsOpCode( const OUString& rName, bool 
bInArray )
         }
         if (!aIntName.isEmpty())
         {
-            maRawToken.SetExternal( aIntName.getStr() );     // international 
name
+            maRawToken.SetExternal( aIntName );     // international name
             bFound = true;
         }
     }
@@ -3374,7 +3374,7 @@ bool ScCompiler::IsMacro( const OUString& rName )
     {
         return false;
     }
-    maRawToken.SetExternal( aName.getStr() );
+    maRawToken.SetExternal( aName );
     maRawToken.eOp = ocMacro;
     return true;
 #endif
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index cdb4bd22a587..857e104f6895 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -320,10 +320,7 @@ void ScRawToken::SetExternalSingleRef( sal_uInt16 nFileId, 
const OUString& rTabN
     extref.nFileId = nFileId;
     extref.aRef.Ref1 =
     extref.aRef.Ref2 = rRef;
-
-    sal_Int32 n = rTabName.getLength();
-    memcpy(extref.cTabName, rTabName.getStr(), n*sizeof(sal_Unicode));
-    extref.cTabName[n] = 0;
+    maExternalName = rTabName;
 }
 
 void ScRawToken::SetExternalDoubleRef( sal_uInt16 nFileId, const OUString& 
rTabName, const ScComplexRefData& rRef )
@@ -333,10 +330,7 @@ void ScRawToken::SetExternalDoubleRef( sal_uInt16 nFileId, 
const OUString& rTabN
 
     extref.nFileId = nFileId;
     extref.aRef = rRef;
-
-    sal_Int32 n = rTabName.getLength();
-    memcpy(extref.cTabName, rTabName.getStr(), n*sizeof(sal_Unicode));
-    extref.cTabName[n] = 0;
+    maExternalName = rTabName;
 }
 
 void ScRawToken::SetExternalName( sal_uInt16 nFileId, const OUString& rName )
@@ -345,22 +339,14 @@ void ScRawToken::SetExternalName( sal_uInt16 nFileId, 
const OUString& rName )
     eType = svExternalName;
 
     extname.nFileId = nFileId;
-
-    sal_Int32 n = rName.getLength();
-    memcpy(extname.cName, rName.getStr(), n*sizeof(sal_Unicode));
-    extname.cName[n] = 0;
+    maExternalName = rName;
 }
 
-void ScRawToken::SetExternal( const sal_Unicode* pStr )
+void ScRawToken::SetExternal( const OUString& rStr )
 {
     eOp   = ocExternal;
     eType = svExternal;
-    sal_Int32 nLen = GetStrLen( pStr ) + 1;
-    if( nLen > MAXSTRLEN )
-        nLen = MAXSTRLEN;
-    // Leave space for byte parameter!
-    memcpy( cStr+1, pStr, nLen * sizeof(sal_Unicode) );
-    cStr[ nLen+1 ] = 0;
+    maExternalName = rStr;
 }
 
 bool ScRawToken::IsValidReference() const
@@ -418,23 +404,23 @@ FormulaToken* ScRawToken::CreateToken() const
                 return new FormulaIndexToken( eOp, name.nIndex, name.nSheet);
         case svExternalSingleRef:
             {
-                svl::SharedString aTabName( OUString( extref.cTabName));    // 
string not interned
+                svl::SharedString aTabName(maExternalName);    // string not 
interned
                 return new ScExternalSingleRefToken(extref.nFileId, aTabName, 
extref.aRef.Ref1);
             }
         case svExternalDoubleRef:
             {
-                svl::SharedString aTabName( OUString( extref.cTabName));    // 
string not interned
+                svl::SharedString aTabName(maExternalName);    // string not 
interned
                 return new ScExternalDoubleRefToken(extref.nFileId, aTabName, 
extref.aRef);
             }
         case svExternalName:
             {
-                svl::SharedString aName( OUString( extname.cName));         // 
string not interned
+                svl::SharedString aName(maExternalName);         // string not 
interned
                 return new ScExternalNameToken( extname.nFileId, aName );
             }
         case svJump :
             return new FormulaJumpToken( eOp, nJump );
         case svExternal :
-            return new FormulaExternalToken( eOp, sbyte.cByte, OUString( 
cStr+1 ) );
+            return new FormulaExternalToken( eOp, sbyte.cByte, maExternalName 
);
         case svFAP :
             return new FormulaFAPToken( eOp, sbyte.cByte, nullptr );
         case svMissing :
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to