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.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2018-08-03 21:44:19 +02:00 committed by Noel Grandin
parent 7989b3951b
commit fc79121c95
3 changed files with 13 additions and 29 deletions

View file

@ -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

View file

@ -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

View file

@ -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 :