Resolves: tdf#95440 SharedString are interned per document, re-intern

... if literal strings are copied with formula expression tokens.

Change-Id: I13526907bb6c2c605c6ed9584fa6e3f2b18623b8
This commit is contained in:
Eike Rathke 2015-12-15 17:44:30 +01:00
parent 07004a7e9c
commit dad412e07f
4 changed files with 40 additions and 0 deletions

View File

@ -204,6 +204,11 @@ svl::SharedString FormulaToken::GetString() const
return svl::SharedString(); // invalid string
}
void FormulaToken::SetString( const svl::SharedString& )
{
SAL_WARN( "formula.core", "FormulaToken::SetString: virtual dummy called" );
}
sal_uInt16 FormulaToken::GetIndex() const
{
SAL_WARN( "formula.core", "FormulaToken::GetIndex: virtual dummy called" );
@ -1523,6 +1528,21 @@ FormulaToken* FormulaTokenArray::AddOpCode( OpCode eOp )
return AddToken( *pRet );
}
void FormulaTokenArray::ReinternStrings( svl::SharedStringPool& rPool )
{
for (sal_uInt16 i=0; i < nLen; ++i)
{
switch (pCode[i]->GetType())
{
case svString:
pCode[i]->SetString( rPool.intern( pCode[i]->GetString().getString()));
break;
default:
; // nothing
}
}
}
/*----------------------------------------------------------------------*/
@ -1651,6 +1671,11 @@ svl::SharedString FormulaStringToken::GetString() const
return maString;
}
void FormulaStringToken::SetString( const svl::SharedString& rStr )
{
maString = rStr;
}
bool FormulaStringToken::operator==( const FormulaToken& r ) const
{
return FormulaToken::operator==( r ) && maString == r.GetString();
@ -1672,6 +1697,11 @@ svl::SharedString FormulaStringOpToken::GetString() const
return maString;
}
void FormulaStringOpToken::SetString( const svl::SharedString& rStr )
{
maString = rStr;
}
bool FormulaStringOpToken::operator==( const FormulaToken& r ) const
{
return FormulaByteToken::operator==( r ) && maString == r.GetString();

View File

@ -151,6 +151,7 @@ public:
virtual double GetDouble() const;
virtual double& GetDoubleAsReference();
virtual svl::SharedString GetString() const;
virtual void SetString( const svl::SharedString& rStr );
virtual sal_uInt16 GetIndex() const;
virtual void SetIndex( sal_uInt16 n );
virtual bool IsGlobal() const;
@ -283,6 +284,7 @@ public:
virtual FormulaToken* Clone() const override;
virtual svl::SharedString GetString() const override;
virtual void SetString( const svl::SharedString& rStr ) override;
virtual bool operator==( const FormulaToken& rToken ) const override;
DECL_FIXEDMEMPOOL_NEWDEL_DLL( FormulaStringToken )
@ -300,6 +302,7 @@ public:
virtual FormulaToken* Clone() const override;
virtual svl::SharedString GetString() const override;
virtual void SetString( const svl::SharedString& rStr ) override;
virtual bool operator==( const FormulaToken& rToken ) const override;
};

View File

@ -309,6 +309,9 @@ public:
/** Determines if this formula may be followed by a reference. */
bool MayReferenceFollow();
/** Re-intern SharedString in case the SharedStringPool differs. */
void ReinternStrings( svl::SharedStringPool& rPool );
};
inline OpCode FormulaTokenArray::GetOuterFuncOpCode()

View File

@ -916,7 +916,11 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons
}
if (!pDocument->IsClipOrUndo())
{
if (&pDocument->GetSharedStringPool() != &rCell.pDocument->GetSharedStringPool())
pCode->ReinternStrings( pDocument->GetSharedStringPool());
pCode->AdjustReferenceOnCopy( aPos);
}
if ( nCloneFlags & SC_CLONECELL_ADJUST3DREL )
pCode->ReadjustRelative3DReferences( rCell.aPos, aPos );