sc/source/core/data/formulacell.cxx | 47 +++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-)
New commits: commit a5867a0d676981c27b36a4def9b423fabf6862e8 Author: Eike Rathke <er...@redhat.com> Date: Tue Mar 22 17:16:07 2016 +0100 Resolves: tdf#98642 comparing RPN insufficient in shared formula detection (cherry picked from commit d6b32653ad34f0879ad1ada421a3a2655dd766e1) Backported. Change-Id: I78812c2d6fdb3464ccc2ebeee901a76f675effa4 Reviewed-on: https://gerrit.libreoffice.org/23436 Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com> Tested-by: Jenkins <c...@libreoffice.org> diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index d9f48e1..eb24423 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -3885,7 +3885,7 @@ ScFormulaCell::CompareState ScFormulaCell::CompareByTokenArray( ScFormulaCell& r break; case formula::svIndex: { - if(pThisTok->GetIndex() != pOtherTok->GetIndex()) + if(pThisTok->GetIndex() != pOtherTok->GetIndex() || pThisTok->IsGlobal() != pOtherTok->IsGlobal()) return NotEqual; } break; @@ -3909,6 +3909,51 @@ ScFormulaCell::CompareState ScFormulaCell::CompareByTokenArray( ScFormulaCell& r } } + // If still the same, check lexical names as different names may result in + // identical RPN code. + + pThis = pCode->GetArray(); + nThisLen = pCode->GetLen(); + pOther = rOther.pCode->GetArray(); + nOtherLen = rOther.pCode->GetLen(); + + if ( !pThis || !pOther ) + { + // Error: no code for cells !" + return NotEqual; + } + + if ( nThisLen != nOtherLen ) + return NotEqual; + + for ( sal_uInt16 i = 0; i < nThisLen; i++ ) + { + formula::FormulaToken *pThisTok = pThis[i]; + formula::FormulaToken *pOtherTok = pOther[i]; + + if ( pThisTok->GetType() != pOtherTok->GetType() || + pThisTok->GetOpCode() != pOtherTok->GetOpCode() || + pThisTok->GetParamCount() != pOtherTok->GetParamCount() ) + { + // Incompatible type, op-code or param counts. + return NotEqual; + } + + switch (pThisTok->GetType()) + { + // All index tokens are names. Different categories already had + // different OpCode values. + case formula::svIndex: + { + if (pThisTok->GetIndex() != pOtherTok->GetIndex() || pThisTok->IsGlobal() != pOtherTok->IsGlobal()) + return NotEqual; + } + break; + default: + ; + } + } + return bInvariant ? EqualInvariant : EqualRelativeRef; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits