Kaydet (Commit) 742b36ed authored tarafından Eike Rathke's avatar Eike Rathke

clone token in ScFormulaResult copy-ctor instead of referring

Replaces commit e2b11f4f

Prevent excessive references to single token instance during fill.

Because if not, we may run out of the 16-bit integer space to
store reference count.
üst 78997434
...@@ -41,6 +41,20 @@ class ScFormulaResult ...@@ -41,6 +41,20 @@ class ScFormulaResult
static const Multiline MULTILINE_FALSE = 1; static const Multiline MULTILINE_FALSE = 1;
static const Multiline MULTILINE_TRUE = 2; static const Multiline MULTILINE_TRUE = 2;
// Clone token if the 16-bit only reference counter is nearing it's
// capacity during fill or copy&paste, leaving 4k for temporary passing
// around. (That should be enough for all times (TM) ;-)
static const sal_uInt16 MAX_TOKENREF_COUNT = 0xf000;
static void IncrementTokenRef( const formula::FormulaToken* & rp )
{
if (rp)
{
if (rp->GetRef() >= MAX_TOKENREF_COUNT)
rp = rp->Clone();
rp->IncRef();
}
}
union union
{ {
double mfValue; // double result direct for performance and memory consumption double mfValue; // double result direct for performance and memory consumption
...@@ -94,8 +108,12 @@ public: ...@@ -94,8 +108,12 @@ public:
const ScMatrixFormulaCellToken* pMatFormula = const ScMatrixFormulaCellToken* pMatFormula =
r.GetMatrixFormulaCellToken(); r.GetMatrixFormulaCellToken();
if (pMatFormula) if (pMatFormula)
{
mpToken = new ScMatrixFormulaCellToken( *pMatFormula); mpToken = new ScMatrixFormulaCellToken( *pMatFormula);
mpToken->IncRef(); mpToken->IncRef();
}
else
IncrementTokenRef( mpToken);
} }
} }
else else
...@@ -308,8 +326,7 @@ inline void ScFormulaResult::Assign( const ScFormulaResult & r ) ...@@ -308,8 +326,7 @@ inline void ScFormulaResult::Assign( const ScFormulaResult & r )
inline void ScFormulaResult::SetToken( const formula::FormulaToken* p ) inline void ScFormulaResult::SetToken( const formula::FormulaToken* p )
{ {
ResetToDefaults(); ResetToDefaults();
if (p) IncrementTokenRef( p);
p->IncRef();
// Handle a result obtained from the interpreter to be assigned to a matrix // Handle a result obtained from the interpreter to be assigned to a matrix
// formula cell's ScMatrixFormulaCellToken. // formula cell's ScMatrixFormulaCellToken.
ScMatrixFormulaCellToken* pMatFormula = GetMatrixFormulaCellTokenNonConst(); ScMatrixFormulaCellToken* pMatFormula = GetMatrixFormulaCellTokenNonConst();
......
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