Resolves: tdf#95440 SharedString are interned per document, re-intern
... if literal strings are copied with formula expression tokens.
(cherry picked from commit dad412e07f805a53ad73ce2e80d187a70c77e8de)
Conflicts:
include/formula/token.hxx
Change-Id: I13526907bb6c2c605c6ed9584fa6e3f2b18623b8
Reviewed-on: https://gerrit.libreoffice.org/20731
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 9f16f4c..a8df239 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -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
}
}
}
/*----------------------------------------------------------------------*/
@@ -1653,6 +1673,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();
@@ -1674,6 +1699,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();
diff --git a/include/formula/token.hxx b/include/formula/token.hxx
index 6d6550b..b0b143e 100644
--- a/include/formula/token.hxx
+++ b/include/formula/token.hxx
@@ -150,7 +150,8 @@ public:
virtual void SetForceArray( bool b );
virtual double GetDouble() const;
virtual double& GetDoubleAsReference();
virtual svl::SharedString GetString() const;
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;
@@ -288,6 +289,7 @@ public:
virtual FormulaToken* Clone() const SAL_OVERRIDE;
virtual svl::SharedString GetString() const SAL_OVERRIDE;
virtual void SetString( const svl::SharedString& rStr ) SAL_OVERRIDE;
virtual bool operator==( const FormulaToken& rToken ) const SAL_OVERRIDE;
DECL_FIXEDMEMPOOL_NEWDEL_DLL( FormulaStringToken )
@@ -305,6 +307,7 @@ public:
virtual FormulaToken* Clone() const SAL_OVERRIDE;
virtual svl::SharedString GetString() const SAL_OVERRIDE;
virtual void SetString( const svl::SharedString& rStr ) SAL_OVERRIDE;
virtual bool operator==( const FormulaToken& rToken ) const SAL_OVERRIDE;
};
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index 58bb092..f907b1c 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -314,6 +314,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()
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 11d56f3..36c64e1 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -853,7 +853,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 );