Kaydet (Commit) c07b8ded authored tarafından Michael Meeks's avatar Michael Meeks

ODS load perf: transfer ownership of the ScTokenArray to save cycles.

Add API to wnsure we don't end up allocating 32k bytes of tokens
for each ScFormulaToken, as happens when you Add a token to a new
empty ScTokenArray.

Change-Id: Ib12a3065eb513243a2146ebb009fbaa650385dd9
üst 7732f806
...@@ -687,6 +687,24 @@ void FormulaTokenArray::Assign( const FormulaTokenArray& r ) ...@@ -687,6 +687,24 @@ void FormulaTokenArray::Assign( const FormulaTokenArray& r )
} }
} }
/// Optimisiation for efficiently creating StringXML placeholders
void FormulaTokenArray::Assign( sal_uInt16 nCode, FormulaToken **pTokens )
{
assert( nLen = 0 );
assert( pCode == NULL );
nLen = nCode;
pCode = new FormulaToken*[ nLen ];
for( sal_uInt16 i = 0; i < nLen; i++ )
{
FormulaToken *t = pTokens[ i ];
assert( t->GetOpCode() == ocStringXML );
pCode[ i ] = t;
t->IncRef();
}
}
FormulaTokenArray& FormulaTokenArray::operator=( const FormulaTokenArray& rArr ) FormulaTokenArray& FormulaTokenArray::operator=( const FormulaTokenArray& rArr )
{ {
Clear(); Clear();
......
...@@ -82,6 +82,7 @@ protected: ...@@ -82,6 +82,7 @@ protected:
protected: protected:
void Assign( const FormulaTokenArray& ); void Assign( const FormulaTokenArray& );
void Assign( sal_uInt16 nCode, FormulaToken **pTokens );
/// Also used by the compiler. The token MUST had been allocated with new! /// Also used by the compiler. The token MUST had been allocated with new!
FormulaToken* Add( FormulaToken* ); FormulaToken* Add( FormulaToken* );
......
...@@ -110,6 +110,9 @@ public: ...@@ -110,6 +110,9 @@ public:
NULL if there is no pCode (which actually would be caller's fault). */ NULL if there is no pCode (which actually would be caller's fault). */
formula::FormulaToken* MergeRangeReference( const ScAddress & rPos ); formula::FormulaToken* MergeRangeReference( const ScAddress & rPos );
/// Assign XML string placeholder to the array
void AssignXMLString( const OUString &rText, const OUString &rFormulaNmsp );
/// Assignment with references to ScToken entries (not copied!) /// Assignment with references to ScToken entries (not copied!)
ScTokenArray& operator=( const ScTokenArray& ); ScTokenArray& operator=( const ScTokenArray& );
......
...@@ -2083,6 +2083,18 @@ FormulaToken* ScTokenArray::AddColRowName( const ScSingleRefData& rRef ) ...@@ -2083,6 +2083,18 @@ FormulaToken* ScTokenArray::AddColRowName( const ScSingleRefData& rRef )
return Add( new ScSingleRefToken( rRef, ocColRowName ) ); return Add( new ScSingleRefToken( rRef, ocColRowName ) );
} }
void ScTokenArray::AssignXMLString( const OUString &rText, const OUString &rFormulaNmsp )
{
sal_uInt16 nTokens = 1;
FormulaToken *aTokens[2];
aTokens[0] = new FormulaStringOpToken( ocStringXML, rText );
if( !rFormulaNmsp.isEmpty() )
aTokens[ nTokens++ ] = new FormulaStringOpToken( ocStringXML, rFormulaNmsp );
Assign( nTokens, aTokens );
}
bool ScTokenArray::GetAdjacentExtendOfOuterFuncRefs( SCCOLROW& nExtend, bool ScTokenArray::GetAdjacentExtendOfOuterFuncRefs( SCCOLROW& nExtend,
const ScAddress& rPos, ScDirection eDir ) const ScAddress& rPos, ScDirection eDir )
{ {
......
...@@ -1362,7 +1362,6 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos ) ...@@ -1362,7 +1362,6 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
ScDocumentImport& rDoc = rXMLImport.GetDoc(); ScDocumentImport& rDoc = rXMLImport.GetDoc();
OUString aText = maFormula->first; OUString aText = maFormula->first;
OUString aFormulaNmsp = maFormula->second;
::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard ( ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard (
new ScExternalRefManager::ApiGuard(pDoc)); new ScExternalRefManager::ApiGuard(pDoc));
...@@ -1372,13 +1371,15 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos ) ...@@ -1372,13 +1371,15 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
if ( aText[0] == '=' && aText.getLength() > 1 ) if ( aText[0] == '=' && aText.getLength() > 1 )
{ {
// temporary formula string as string tokens // temporary formula string as string tokens
boost::scoped_ptr<ScTokenArray> pCode(new ScTokenArray); ScTokenArray *pCode = new ScTokenArray();
pCode->AddStringXML( aText );
if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() ) OUString aFormulaNmsp = maFormula->second;
pCode->AddStringXML( aFormulaNmsp ); if( eGrammar != formula::FormulaGrammar::GRAM_EXTERNAL )
aFormulaNmsp = OUString();
pCode->AssignXMLString( aText, aFormulaNmsp );
rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() ); rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() );
ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, *pCode, eGrammar, MM_NONE); ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, pCode, eGrammar, MM_NONE);
SetFormulaCell(pNewCell); SetFormulaCell(pNewCell);
rDoc.setFormulaCell(rCellPos, pNewCell); rDoc.setFormulaCell(rCellPos, pNewCell);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment