[Libreoffice-commits] core.git: sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 10 11:00:34 UTC 2018


 sc/source/filter/excel/excform.cxx           |   28 +++++++++++++--------------
 sc/source/filter/excel/excform8.cxx          |   20 +++++++++----------
 sc/source/filter/excel/impop.cxx             |   16 ++++++++-------
 sc/source/filter/excel/tokstack.cxx          |   12 ++++-------
 sc/source/filter/excel/xichart.cxx           |    4 +--
 sc/source/filter/excel/xicontent.cxx         |   16 +++++++--------
 sc/source/filter/excel/xiformula.cxx         |    8 +++----
 sc/source/filter/excel/xihelper.cxx          |    4 +--
 sc/source/filter/excel/xilink.cxx            |    4 +--
 sc/source/filter/excel/xiname.cxx            |   10 ++++-----
 sc/source/filter/excel/xipivot.cxx           |    6 +++--
 sc/source/filter/inc/XclImpChangeTrack.hxx   |    2 -
 sc/source/filter/inc/excform.hxx             |   12 +++++------
 sc/source/filter/inc/formel.hxx              |    4 +--
 sc/source/filter/inc/imp_op.hxx              |    2 -
 sc/source/filter/inc/lotform.hxx             |    2 -
 sc/source/filter/inc/qproform.hxx            |    2 -
 sc/source/filter/inc/tokstack.hxx            |   15 ++++++--------
 sc/source/filter/inc/xiformula.hxx           |    7 +-----
 sc/source/filter/lotus/lotform.cxx           |    6 ++---
 sc/source/filter/lotus/lotimpop.cxx          |    4 +--
 sc/source/filter/lotus/op.cxx                |    8 +++----
 sc/source/filter/qpro/qpro.cxx               |    4 +--
 sc/source/filter/qpro/qproform.cxx           |    4 +--
 sc/source/filter/xcl97/XclImpChangeTrack.cxx |   11 ++++------
 25 files changed, 104 insertions(+), 107 deletions(-)

New commits:
commit caf0595f05c0b9199c28c96415878ffc22cb05ec
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Tue Sep 18 15:02:33 2018 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Wed Oct 10 13:00:07 2018 +0200

    do not needlessly create ScTokenArray copies in Calc input filters
    
    It doesn't make much sense to keep around one ScTokenArray, pass
    it around, use a copy of it and then Clear() the original.
    
    Change-Id: I8636b32dc9b547b4b649c8d811c8425530896100
    Reviewed-on: https://gerrit.libreoffice.org/60863
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx
index 57038e36bd2d..7a2f80ef5fbc 100644
--- a/sc/source/filter/excel/excform.cxx
+++ b/sc/source/filter/excel/excform.cxx
@@ -107,7 +107,7 @@ void ImportExcel::Formula(
         return;
 
     // Formula will be read next, length in nFormLen
-    const ScTokenArray* pResult = nullptr;
+    std::unique_ptr<ScTokenArray> pResult;
 
     pFormConv->Reset( aScPos );
     ScDocumentImport& rDoc = GetDocImport();
@@ -157,7 +157,7 @@ void ImportExcel::Formula(
 
     if (pResult)
     {
-        pCell = new ScFormulaCell(&rDoc.getDoc(), aScPos, *pResult);
+        pCell = new ScFormulaCell(&rDoc.getDoc(), aScPos, pResult.release());
         pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8);
         rDoc.getDoc().CheckLinkFormulaNeedingCheck( *pCell->GetCode());
         rDoc.getDoc().EnsureTable(aScPos.Tab());
@@ -196,17 +196,17 @@ ExcelToSc::~ExcelToSc()
 {
 }
 
-void ExcelToSc::GetDummy( const ScTokenArray*& pResult )
+std::unique_ptr<ScTokenArray> ExcelToSc::GetDummy()
 {
     aPool.Store( OUString("Dummy()") );
     aPool >> aStack;
-    pResult = aPool[ aStack.Get() ];
+    return aPool.GetTokenArray( aStack.Get());
 }
 
 // if bAllowArrays is false stream seeks to first byte after <nFormulaLen>
 // otherwise it will seek to the first byte after the additional content (eg
 // inline arrays) following <nFormulaLen>
-ConvErr ExcelToSc::Convert( const ScTokenArray*& pResult, XclImpStream& aIn, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT )
+ConvErr ExcelToSc::Convert( std::unique_ptr<ScTokenArray>& pResult, XclImpStream& aIn, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT )
 {
     RootData&       rR = GetOldRoot();
     sal_uInt8           nOp, nLen;
@@ -232,7 +232,7 @@ ConvErr ExcelToSc::Convert( const ScTokenArray*& pResult, XclImpStream& aIn, std
     {
         aPool.Store( OUString("-/-") );
         aPool >> aStack;
-        pResult = aPool[ aStack.Get() ];
+        pResult = aPool.GetTokenArray( aStack.Get());
         return ConvErr::OK;
     }
 
@@ -870,14 +870,14 @@ ConvErr ExcelToSc::Convert( const ScTokenArray*& pResult, XclImpStream& aIn, std
     {
         aPool << ocBad;
         aPool >> aStack;
-        pResult = aPool[ aStack.Get() ];
+        pResult = aPool.GetTokenArray( aStack.Get());
         eRet = ConvErr::Ni;
     }
     else if( aIn.GetRecPos() != nEndPos )
     {
         aPool << ocBad;
         aPool >> aStack;
-        pResult = aPool[ aStack.Get() ];
+        pResult = aPool.GetTokenArray( aStack.Get());
         eRet = ConvErr::Count;
     }
     else if( bArrayFormula )
@@ -887,7 +887,7 @@ ConvErr ExcelToSc::Convert( const ScTokenArray*& pResult, XclImpStream& aIn, std
     }
     else
     {
-        pResult = aPool[ aStack.Get() ];
+        pResult = aPool.GetTokenArray( aStack.Get());
         eRet = ConvErr::OK;
     }
 
@@ -1326,7 +1326,7 @@ ConvErr ExcelToSc::Convert( ScRangeListTabs& rRangeList, XclImpStream& aIn, std:
     return eRet;
 }
 
-void ExcelToSc::ConvertExternName( const ScTokenArray*& /*rpArray*/, XclImpStream& /*rStrm*/, std::size_t /*nFormulaLen*/,
+void ExcelToSc::ConvertExternName( std::unique_ptr<ScTokenArray>& /*rpArray*/, XclImpStream& /*rStrm*/, std::size_t /*nFormulaLen*/,
                                       const OUString& /*rUrl*/, const vector<OUString>& /*rTabNames*/ )
 {
 }
@@ -1676,7 +1676,7 @@ void ExcelToSc::ExcRelToScRel( sal_uInt16 nRow, sal_uInt8 nCol, ScSingleRefData
     }
 }
 
-const ScTokenArray* ExcelToSc::GetBoolErr( XclBoolError eType )
+std::unique_ptr<ScTokenArray> ExcelToSc::GetBoolErr( XclBoolError eType )
 {
     FormulaError nError;
     aPool.Reset();
@@ -1708,11 +1708,11 @@ const ScTokenArray* ExcelToSc::GetBoolErr( XclBoolError eType )
 
     aPool >> aStack;
 
-    const ScTokenArray*     pResult = aPool[ aStack.Get() ];
+    std::unique_ptr<ScTokenArray> pResult = aPool.GetTokenArray( aStack.Get());
     if( nError != FormulaError::NONE )
-        const_cast<ScTokenArray*>(pResult)->SetCodeError( nError );
+        pResult->SetCodeError( nError );
 
-    const_cast<ScTokenArray*>(pResult)->SetExclusiveRecalcModeNormal();
+    pResult->SetExclusiveRecalcModeNormal();
 
     return pResult;
 }
diff --git a/sc/source/filter/excel/excform8.cxx b/sc/source/filter/excel/excform8.cxx
index 515e89ca2c53..6cec86f94b11 100644
--- a/sc/source/filter/excel/excform8.cxx
+++ b/sc/source/filter/excel/excform8.cxx
@@ -135,7 +135,7 @@ bool ExcelToSc8::HandleOleLink(sal_uInt16 nXtiIndex, const XclImpExtName& rExtNa
 
 // if bAllowArrays is false stream seeks to first byte after <nFormulaLen>
 // otherwise it will seek to the first byte past additional content after <nFormulaLen>
-ConvErr ExcelToSc8::Convert( const ScTokenArray*& rpTokArray, XclImpStream& aIn, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT )
+ConvErr ExcelToSc8::Convert( std::unique_ptr<ScTokenArray>& rpTokArray, XclImpStream& aIn, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT )
 {
     bool                    bError = false;
     bool                    bArrayFormula = false;
@@ -160,7 +160,7 @@ ConvErr ExcelToSc8::Convert( const ScTokenArray*& rpTokArray, XclImpStream& aIn,
     {
         aPool.Store( OUString( "-/-" ) );
         aPool >> aStack;
-        rpTokArray = aPool[ aStack.Get() ];
+        rpTokArray = aPool.GetTokenArray( aStack.Get());
         return ConvErr::OK;
     }
 
@@ -924,14 +924,14 @@ ConvErr ExcelToSc8::Convert( const ScTokenArray*& rpTokArray, XclImpStream& aIn,
     {
         aPool << ocBad;
         aPool >> aStack;
-        rpTokArray = aPool[ aStack.Get() ];
+        rpTokArray = aPool.GetTokenArray( aStack.Get());
         eRet = ConvErr::Ni;
     }
     else if( aIn.GetRecPos() != nEndPos )
     {
         aPool << ocBad;
         aPool >> aStack;
-        rpTokArray = aPool[ aStack.Get() ];
+        rpTokArray = aPool.GetTokenArray( aStack.Get());
         eRet = ConvErr::Count;
     }
     else if( bArrayFormula )
@@ -941,7 +941,7 @@ ConvErr ExcelToSc8::Convert( const ScTokenArray*& rpTokArray, XclImpStream& aIn,
     }
     else
     {
-        rpTokArray = aPool[ aStack.Get() ];
+        rpTokArray = aPool.GetTokenArray( aStack.Get());
         eRet = ConvErr::OK;
     }
 
@@ -1297,7 +1297,7 @@ ConvErr ExcelToSc8::Convert( ScRangeListTabs& rRangeList, XclImpStream& aIn, std
     return eRet;
 }
 
-void ExcelToSc8::ConvertExternName( const ScTokenArray*& rpArray, XclImpStream& rStrm, std::size_t nFormulaLen,
+void ExcelToSc8::ConvertExternName( std::unique_ptr<ScTokenArray>& rpArray, XclImpStream& rStrm, std::size_t nFormulaLen,
                                        const OUString& rUrl, const vector<OUString>& rTabNames )
 {
     if( !GetDocShell() )
@@ -1321,7 +1321,7 @@ void ExcelToSc8::ConvertExternName( const ScTokenArray*& rpArray, XclImpStream&
     {
         aPool.Store(OUString("-/-"));
         aPool >> aStack;
-        rpArray = aPool[aStack.Get()];
+        rpArray = aPool.GetTokenArray( aStack.Get());
         return;
     }
 
@@ -1430,17 +1430,17 @@ void ExcelToSc8::ConvertExternName( const ScTokenArray*& rpArray, XclImpStream&
     {
         aPool << ocBad;
         aPool >> aStack;
-        rpArray = aPool[ aStack.Get() ];
+        rpArray = aPool.GetTokenArray( aStack.Get());
     }
     else if( rStrm.GetRecPos() != nEndPos )
     {
         aPool << ocBad;
         aPool >> aStack;
-        rpArray = aPool[ aStack.Get() ];
+        rpArray = aPool.GetTokenArray( aStack.Get());
     }
     else
     {
-        rpArray = aPool[ aStack.Get() ];
+        rpArray = aPool.GetTokenArray( aStack.Get());
     }
 
     rStrm.Seek(nEndPos);
diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx
index ceb03131f015..9394585e6920 100644
--- a/sc/source/filter/excel/impop.cxx
+++ b/sc/source/filter/excel/impop.cxx
@@ -386,8 +386,10 @@ void ImportExcel::ReadBoolErr()
             GetXFRangeBuffer().SetXF( aScPos, nXFIdx );
 
         double fValue;
-        const ScTokenArray* pScTokArr = ErrorToFormula( nType != EXC_BOOLERR_BOOL, nValue, fValue );
-        ScFormulaCell* pCell = pScTokArr ? new ScFormulaCell(pD, aScPos, *pScTokArr) : new ScFormulaCell(pD, aScPos);
+        std::unique_ptr<ScTokenArray> pScTokArr = ErrorToFormula( nType != EXC_BOOLERR_BOOL, nValue, fValue );
+        ScFormulaCell* pCell = pScTokArr
+            ? new ScFormulaCell(pD, aScPos, pScTokArr.release())
+            : new ScFormulaCell(pD, aScPos);
         pCell->SetHybridDouble( fValue );
         GetDocImport().setFormulaCell(aScPos, pCell);
     }
@@ -537,7 +539,7 @@ void ImportExcel::Array25()
         nFormLen = aIn.ReaduInt16();
     }
 
-    const ScTokenArray* pResult = nullptr;
+    std::unique_ptr<ScTokenArray> pResult;
 
     if (ValidColRow(nLastCol, nLastRow))
     {
@@ -844,7 +846,7 @@ void ImportExcel::Shrfmla()
 
     // read mark is now on the formula
 
-    const ScTokenArray* pResult;
+    std::unique_ptr<ScTokenArray> pResult;
 
     // The shared range in this record is erroneous more than half the time.
     // Don't ever rely on it. Use the one from the formula cell above.
@@ -867,7 +869,7 @@ void ImportExcel::Shrfmla()
 
     ScDocumentImport& rDoc = GetDocImport();
 
-    ScFormulaCell* pCell = new ScFormulaCell(pD, aPos, *pResult);
+    ScFormulaCell* pCell = new ScFormulaCell(pD, aPos, pResult.release());
     pCell->GetCode()->WrapReference(aPos, EXC_MAXCOL8, EXC_MAXROW8);
     rDoc.getDoc().CheckLinkFormulaNeedingCheck( *pCell->GetCode());
     rDoc.getDoc().EnsureTable(aPos.Tab());
@@ -1035,7 +1037,7 @@ void ImportExcel::Array34()
     aIn.Ignore( (GetBiff() >= EXC_BIFF5) ? 6 : 2 );
     nFormLen = aIn.ReaduInt16();
 
-    const ScTokenArray* pResult = nullptr;
+    std::unique_ptr<ScTokenArray> pResult;
 
     if( ValidColRow( nLastCol, nLastRow ) )
     {
@@ -1244,7 +1246,7 @@ void ImportExcel::NewTable()
     pRowOutlineBuff = pNewItem->GetRowOutline();
 }
 
-const ScTokenArray* ImportExcel::ErrorToFormula( bool bErrOrVal, sal_uInt8 nError, double& rVal )
+std::unique_ptr<ScTokenArray> ImportExcel::ErrorToFormula( bool bErrOrVal, sal_uInt8 nError, double& rVal )
 {
     return pFormConv->GetBoolErr( XclTools::ErrorToEnum( rVal, bErrOrVal, nError ) );
 }
diff --git a/sc/source/filter/excel/tokstack.cxx b/sc/source/filter/excel/tokstack.cxx
index f28705fd755a..c4b067db2b7e 100644
--- a/sc/source/filter/excel/tokstack.cxx
+++ b/sc/source/filter/excel/tokstack.cxx
@@ -63,8 +63,6 @@ TokenPool::TokenPool( svl::SharedStringPool& rSPool ) :
     ppP_Matrix.reset( new ScMatrix*[ nP_Matrix ] );
     memset( ppP_Matrix.get(), 0, sizeof( ScMatrix* ) * nP_Matrix );
 
-    pScToken.reset(new ScTokenArray);
-
     Reset();
 }
 
@@ -174,7 +172,7 @@ bool TokenPool::GrowMatrix()
     return true;
 }
 
-bool TokenPool::GetElement( const sal_uInt16 nId )
+bool TokenPool::GetElement( const sal_uInt16 nId, ScTokenArray* pScToken )
 {
     if (nId >= nElementCurrent)
     {
@@ -184,7 +182,7 @@ bool TokenPool::GetElement( const sal_uInt16 nId )
 
     bool bRet = true;
     if( pType[ nId ] == T_Id )
-        bRet = GetElementRek( nId );
+        bRet = GetElementRek( nId, pScToken );
     else
     {
         switch( pType[ nId ] )
@@ -336,7 +334,7 @@ bool TokenPool::GetElement( const sal_uInt16 nId )
     return bRet;
 }
 
-bool TokenPool::GetElementRek( const sal_uInt16 nId )
+bool TokenPool::GetElementRek( const sal_uInt16 nId, ScTokenArray* pScToken )
 {
 #ifdef DBG_UTIL
     m_nRek++;
@@ -392,9 +390,9 @@ bool TokenPool::GetElementRek( const sal_uInt16 nId )
             else
             {
                 if (pType[ *pCurrent ] == T_Id)
-                    bRet = GetElementRek( *pCurrent );
+                    bRet = GetElementRek( *pCurrent, pScToken );
                 else
-                    bRet = GetElement( *pCurrent );
+                    bRet = GetElement( *pCurrent, pScToken );
             }
         }
         else    // elementary SC_Token
diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx
index fbe65d55f897..6ff977f9d7a6 100644
--- a/sc/source/filter/excel/xichart.cxx
+++ b/sc/source/filter/excel/xichart.cxx
@@ -754,8 +754,8 @@ void XclImpChSourceLink::ReadChSourceLink( XclImpStream& rStrm )
         rStrm >> aXclTokArr;
 
         // convert BIFF formula tokens to Calc token array
-        if( const ScTokenArray* pTokens = GetFormulaCompiler().CreateFormula( EXC_FMLATYPE_CHART, aXclTokArr ) )
-            mxTokenArray.reset( pTokens->Clone() );
+        if( std::unique_ptr<ScTokenArray> pTokens = GetFormulaCompiler().CreateFormula( EXC_FMLATYPE_CHART, aXclTokArr ) )
+            mxTokenArray = std::move( pTokens );
     }
 
     // try to read a following CHSTRING record
diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx
index 9fbd5806824b..ef72040f3c28 100644
--- a/sc/source/filter/excel/xicontent.cxx
+++ b/sc/source/filter/excel/xicontent.cxx
@@ -658,13 +658,13 @@ void XclImpCondFormat::ReadCF( XclImpStream& rStrm )
     ::std::unique_ptr< ScTokenArray > xTokArr1;
     if( nFmlaSize1 > 0 )
     {
-        const ScTokenArray* pTokArr = nullptr;
+        std::unique_ptr<ScTokenArray> pTokArr;
         rFmlaConv.Reset( rPos );
         rFmlaConv.Convert( pTokArr, rStrm, nFmlaSize1, false, FT_CondFormat );
         // formula converter owns pTokArr -> create a copy of the token array
         if( pTokArr )
         {
-            xTokArr1.reset( pTokArr->Clone() );
+            xTokArr1 = std::move( pTokArr );
             GetDocRef().CheckLinkFormulaNeedingCheck( *xTokArr1);
         }
     }
@@ -672,13 +672,13 @@ void XclImpCondFormat::ReadCF( XclImpStream& rStrm )
     ::std::unique_ptr< ScTokenArray > xTokArr2;
     if( nFmlaSize2 > 0 )
     {
-        const ScTokenArray* pTokArr = nullptr;
+        std::unique_ptr<ScTokenArray> pTokArr;
         rFmlaConv.Reset( rPos );
         rFmlaConv.Convert( pTokArr, rStrm, nFmlaSize2, false, FT_CondFormat );
         // formula converter owns pTokArr -> create a copy of the token array
         if( pTokArr )
         {
-            xTokArr2.reset( pTokArr->Clone() );
+            xTokArr2 = std::move( pTokArr );
             GetDocRef().CheckLinkFormulaNeedingCheck( *xTokArr2);
         }
     }
@@ -832,23 +832,23 @@ void XclImpValidationManager::ReadDV( XclImpStream& rStrm )
     rStrm.RestorePosition(aPosFormula1);
     if( nLenFormula1 > 0 )
     {
-        const ScTokenArray* pTokArr = nullptr;
+        std::unique_ptr<ScTokenArray> pTokArr;
         rFmlaConv.Reset(aCombinedRange.aStart);
         rFmlaConv.Convert( pTokArr, rStrm, nLenFormula1, false, FT_CondFormat );
         // formula converter owns pTokArr -> create a copy of the token array
         if( pTokArr )
-            xTokArr1.reset( pTokArr->Clone() );
+            xTokArr1 = std::move( pTokArr );
     }
     rStrm.SetNulSubstChar();    // back to default
     if (nLenFormula2 > 0)
     {
         rStrm.RestorePosition(aPosFormula2);
-        const ScTokenArray* pTokArr = nullptr;
+        std::unique_ptr<ScTokenArray> pTokArr;
         rFmlaConv.Reset(aCombinedRange.aStart);
         rFmlaConv.Convert( pTokArr, rStrm, nLenFormula2, false, FT_CondFormat );
         // formula converter owns pTokArr -> create a copy of the token array
         if( pTokArr )
-            xTokArr2.reset( pTokArr->Clone() );
+            xTokArr2 = std::move( pTokArr );
     }
 
     rStrm.RestorePosition(aCurrentPos);
diff --git a/sc/source/filter/excel/xiformula.cxx b/sc/source/filter/excel/xiformula.cxx
index e2f0f9cb1cf7..7a5fc80557d6 100644
--- a/sc/source/filter/excel/xiformula.cxx
+++ b/sc/source/filter/excel/xiformula.cxx
@@ -36,7 +36,7 @@ public:
                             ScRangeList& rScRanges, XclFormulaType eType,
                             const XclTokenArray& rXclTokArr, XclImpStream& rStrm );
 
-    const ScTokenArray* CreateFormula( XclFormulaType eType, const XclTokenArray& rXclTokArr );
+    std::unique_ptr<ScTokenArray> CreateFormula( XclFormulaType eType, const XclTokenArray& rXclTokArr );
 
 };
 
@@ -63,7 +63,7 @@ void XclImpFmlaCompImpl::CreateRangeList(
     }
 }
 
-const ScTokenArray* XclImpFmlaCompImpl::CreateFormula(
+std::unique_ptr<ScTokenArray> XclImpFmlaCompImpl::CreateFormula(
         XclFormulaType /*eType*/, const XclTokenArray& rXclTokArr )
 {
     if (rXclTokArr.Empty())
@@ -75,7 +75,7 @@ const ScTokenArray* XclImpFmlaCompImpl::CreateFormula(
     aMemStrm.WriteBytes(rXclTokArr.GetData(), rXclTokArr.GetSize());
     XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
     aFmlaStrm.StartNextRecord();
-    const ScTokenArray* pArray = nullptr;
+    std::unique_ptr<ScTokenArray> pArray;
     GetOldFmlaConverter().Reset();
     GetOldFmlaConverter().Convert(pArray, aFmlaStrm, aFmlaStrm.GetRecSize(), true);
     return pArray;
@@ -98,7 +98,7 @@ void XclImpFormulaCompiler::CreateRangeList(
     mxImpl->CreateRangeList( rScRanges, eType, rXclTokArr, rStrm );
 }
 
-const ScTokenArray* XclImpFormulaCompiler::CreateFormula(
+std::unique_ptr<ScTokenArray> XclImpFormulaCompiler::CreateFormula(
         XclFormulaType eType, const XclTokenArray& rXclTokArr )
 {
     return mxImpl->CreateFormula(eType, rXclTokArr);
diff --git a/sc/source/filter/excel/xihelper.cxx b/sc/source/filter/excel/xihelper.cxx
index 93287121b554..5e60ef986917 100644
--- a/sc/source/filter/excel/xihelper.cxx
+++ b/sc/source/filter/excel/xihelper.cxx
@@ -794,10 +794,10 @@ XclImpCachedValue::XclImpCachedValue( XclImpStream& rStrm ) :
             mnBoolErr = rStrm.ReaduInt8();
             rStrm.Ignore( 7 );
 
-            const ScTokenArray* pScTokArr = rStrm.GetRoot().GetOldFmlaConverter().GetBoolErr(
+            std::unique_ptr<ScTokenArray> pScTokArr = rStrm.GetRoot().GetOldFmlaConverter().GetBoolErr(
                 XclTools::ErrorToEnum( fVal, mnType == EXC_CACHEDVAL_ERROR, mnBoolErr ) );
             if( pScTokArr )
-                mxTokArr.reset( pScTokArr->Clone() );
+                mxTokArr = std::move( pScTokArr );
         }
         break;
         default:
diff --git a/sc/source/filter/excel/xilink.cxx b/sc/source/filter/excel/xilink.cxx
index ce811f2471e9..48905964378d 100644
--- a/sc/source/filter/excel/xilink.cxx
+++ b/sc/source/filter/excel/xilink.cxx
@@ -382,7 +382,7 @@ XclImpExtName::XclImpExtName( XclImpSupbook& rSupbook, XclImpStream& rStrm, XclS
             {
                 if (pFormulaConv)
                 {
-                    const ScTokenArray* pArray = nullptr;
+                    std::unique_ptr<ScTokenArray> pArray;
                     sal_uInt16 nFmlaLen;
                     nFmlaLen = rStrm.ReaduInt16();
                     std::vector<OUString> aTabNames;
@@ -393,7 +393,7 @@ XclImpExtName::XclImpExtName( XclImpSupbook& rSupbook, XclImpStream& rStrm, XclS
 
                     pFormulaConv->ConvertExternName(pArray, rStrm, nFmlaLen, rSupbook.GetXclUrl(), aTabNames);
                     if (pArray)
-                        mxArray.reset(pArray->Clone());
+                        mxArray = std::move( pArray );
                 }
             }
         break;
diff --git a/sc/source/filter/excel/xiname.cxx b/sc/source/filter/excel/xiname.cxx
index 720e61953d0f..0e53b619df91 100644
--- a/sc/source/filter/excel/xiname.cxx
+++ b/sc/source/filter/excel/xiname.cxx
@@ -144,12 +144,12 @@ XclImpName::XclImpName( XclImpStream& rStrm, sal_uInt16 nXclNameIdx ) :
     // 3) *** convert the name definition formula *** -------------------------
 
     rFmlaConv.Reset();
-    const ScTokenArray* pTokArr = nullptr; // pointer to token array, owned by rFmlaConv
+    std::unique_ptr<ScTokenArray> pTokArr;
 
     if( ::get_flag( nFlags, EXC_NAME_BIG ) )
     {
         // special, unsupported name
-        rFmlaConv.GetDummy( pTokArr );
+        pTokArr = rFmlaConv.GetDummy();
     }
     else if( bBuiltIn )
     {
@@ -209,7 +209,7 @@ XclImpName::XclImpName( XclImpStream& rStrm, sal_uInt16 nXclNameIdx ) :
     }
 
     if (pTokArr && !bFunction && !mbVBName)
-        InsertName(pTokArr);
+        InsertName(pTokArr.get());
 }
 
 void XclImpName::ConvertTokens()
@@ -219,7 +219,7 @@ void XclImpName::ConvertTokens()
 
     ExcelToSc& rFmlaConv = GetOldFmlaConverter();
     rFmlaConv.Reset();
-    const ScTokenArray* pArray = nullptr;
+    std::unique_ptr<ScTokenArray> pArray;
 
     XclImpStreamPos aOldPos;
     XclImpStream& rStrm = mpTokensData->mrStrm;
@@ -229,7 +229,7 @@ void XclImpName::ConvertTokens()
     rStrm.RestorePosition(aOldPos);
 
     if (pArray)
-        InsertName(pArray);
+        InsertName(pArray.get());
 
     mpTokensData.reset();
 }
diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx
index b46439abbb28..90d512546980 100644
--- a/sc/source/filter/excel/xipivot.cxx
+++ b/sc/source/filter/excel/xipivot.cxx
@@ -118,9 +118,11 @@ void XclImpPCItem::WriteToSource( XclImpRoot& rRoot, const ScAddress& rScPos ) c
     {
         double fValue;
         sal_uInt8 nErrCode = static_cast< sal_uInt8 >( *pnError );
-        const ScTokenArray* pScTokArr = rRoot.GetOldFmlaConverter().GetBoolErr(
+        std::unique_ptr<ScTokenArray> pScTokArr = rRoot.GetOldFmlaConverter().GetBoolErr(
             XclTools::ErrorToEnum( fValue, true, nErrCode ) );
-        ScFormulaCell* pCell = pScTokArr ? new ScFormulaCell(&rDoc.getDoc(), rScPos, *pScTokArr) : new ScFormulaCell(&rDoc.getDoc(), rScPos);
+        ScFormulaCell* pCell = pScTokArr
+            ? new ScFormulaCell(&rDoc.getDoc(), rScPos, pScTokArr.release())
+            : new ScFormulaCell(&rDoc.getDoc(), rScPos);
         pCell->SetHybridDouble( fValue );
         rDoc.setFormulaCell(rScPos, pCell);
     }
diff --git a/sc/source/filter/inc/XclImpChangeTrack.hxx b/sc/source/filter/inc/XclImpChangeTrack.hxx
index 96146d5a3e78..f89a5f068bef 100644
--- a/sc/source/filter/inc/XclImpChangeTrack.hxx
+++ b/sc/source/filter/inc/XclImpChangeTrack.hxx
@@ -78,7 +78,7 @@ private:
     bool                        CheckRecord( sal_uInt16 nOpCode );
 
     void                        ReadFormula(
-                                    ScTokenArray*& rpTokenArray,
+                                    std::unique_ptr<ScTokenArray>& rpTokenArray,
                                     const ScAddress& rPosition );
     void ReadCell( ScCellValue& rCell, sal_uInt32& rFormat, sal_uInt16 nFlags, const ScAddress& rPosition );
 
diff --git a/sc/source/filter/inc/excform.hxx b/sc/source/filter/inc/excform.hxx
index 4345d9daabfc..4851952b4f0c 100644
--- a/sc/source/filter/inc/excform.hxx
+++ b/sc/source/filter/inc/excform.hxx
@@ -48,18 +48,18 @@ protected:
 public:
     ExcelToSc( XclImpRoot& rRoot );
     virtual             ~ExcelToSc() override;
-    virtual ConvErr     Convert( const ScTokenArray*&, XclImpStream& rStrm, std::size_t nFormulaLen,
+    virtual ConvErr     Convert( std::unique_ptr<ScTokenArray>&, XclImpStream& rStrm, std::size_t nFormulaLen,
                                  bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) override;
 
     virtual ConvErr     Convert( ScRangeListTabs&, XclImpStream& rStrm, std::size_t nFormulaLen, SCTAB nTab, const FORMULA_TYPE eFT = FT_CellFormula ) override;
 
-    virtual void        ConvertExternName( const ScTokenArray*& rpArray, XclImpStream& rStrm, std::size_t nFormulaLen,
+    virtual void        ConvertExternName( std::unique_ptr<ScTokenArray>& rpArray, XclImpStream& rStrm, std::size_t nFormulaLen,
                                            const OUString& rUrl, const ::std::vector<OUString>& rTabNames );
 
     virtual void        GetAbsRefs( ScRangeList& rRangeList, XclImpStream& rStrm, std::size_t nLen );
 
-    void                GetDummy( const ScTokenArray*& );
-    const ScTokenArray* GetBoolErr( XclBoolError );
+    std::unique_ptr<ScTokenArray> GetDummy();
+    std::unique_ptr<ScTokenArray> GetBoolErr( XclBoolError );
 
     static bool ReadSharedFormulaPosition( XclImpStream& rStrm, SCCOL& rCol, SCROW& rRow );
     const ScTokenArray* GetSharedFormula( const ScAddress& rRefPos ) const;
@@ -122,11 +122,11 @@ public:
     ExcelToSc8( XclImpRoot& rRoot );
     virtual             ~ExcelToSc8() override;
 
-    virtual ConvErr     Convert( const ScTokenArray*& rpTokArray, XclImpStream& rStrm, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) override;
+    virtual ConvErr     Convert( std::unique_ptr<ScTokenArray>& rpTokArray, XclImpStream& rStrm, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) override;
 
     virtual ConvErr     Convert( ScRangeListTabs&, XclImpStream& rStrm, std::size_t nFormulaLen, SCTAB nTab, const FORMULA_TYPE eFT = FT_CellFormula ) override;
 
-    virtual void        ConvertExternName( const ScTokenArray*& rpArray, XclImpStream& rStrm, std::size_t nFormulaLen,
+    virtual void        ConvertExternName( std::unique_ptr<ScTokenArray>& rpArray, XclImpStream& rStrm, std::size_t nFormulaLen,
                                            const OUString& rUrl, const ::std::vector<OUString>& rTabNames ) override;
 
     static inline bool  IsComplRowRange( const sal_uInt16 nRow1, const sal_uInt16 nRow2 );
diff --git a/sc/source/filter/inc/formel.hxx b/sc/source/filter/inc/formel.hxx
index 2f82381b6ee3..ff6fd422448d 100644
--- a/sc/source/filter/inc/formel.hxx
+++ b/sc/source/filter/inc/formel.hxx
@@ -99,7 +99,7 @@ public:
     void                Reset();
     void                Reset( const ScAddress& rEingPos );
 
-    virtual ConvErr     Convert( const ScTokenArray*& rpErg, XclImpStream& rStrm, std::size_t nFormulaLen,
+    virtual ConvErr     Convert( std::unique_ptr<ScTokenArray>& rpErg, XclImpStream& rStrm, std::size_t nFormulaLen,
                                  bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
     virtual ConvErr     Convert( ScRangeListTabs&, XclImpStream& rStrm, std::size_t nFormulaLen, SCTAB nTab,
                                     const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
@@ -124,7 +124,7 @@ protected:
 public:
     void                Reset( const ScAddress& rEingPos );
 
-    virtual void        Convert( const ScTokenArray*& rpErg, sal_Int32& nRest ) = 0;
+    virtual void        Convert( std::unique_ptr<ScTokenArray>& rpErg, sal_Int32& nRest ) = 0;
 
     bool good() const { return aIn.good(); }
 
diff --git a/sc/source/filter/inc/imp_op.hxx b/sc/source/filter/inc/imp_op.hxx
index 6120da506958..2579446800b7 100644
--- a/sc/source/filter/inc/imp_op.hxx
+++ b/sc/source/filter/inc/imp_op.hxx
@@ -186,7 +186,7 @@ protected:
 
     virtual void            EndSheet();
     void                    NewTable();
-    const ScTokenArray*     ErrorToFormula( bool bErrOrVal, sal_uInt8 nError,
+    std::unique_ptr<ScTokenArray> ErrorToFormula( bool bErrOrVal, sal_uInt8 nError,
                                 double& rVal );
 
     void            AdjustRowHeight();
diff --git a/sc/source/filter/inc/lotform.hxx b/sc/source/filter/inc/lotform.hxx
index f902fd67a893..a352b5c9bd91 100644
--- a/sc/source/filter/inc/lotform.hxx
+++ b/sc/source/filter/inc/lotform.hxx
@@ -88,7 +88,7 @@ private:
 public:
     LotusToSc(LotusContext &rContext, SvStream& aStr, svl::SharedStringPool& rSPool, rtl_TextEncoding eSrc, bool b);
 
-    virtual void        Convert( const ScTokenArray*& rpErg, sal_Int32& nRest ) override;
+    virtual void        Convert( std::unique_ptr<ScTokenArray>& rpErg, sal_Int32& nRest ) override;
 
     void                Reset( const ScAddress& rEingPos );
     inline void         SetWK3();
diff --git a/sc/source/filter/inc/qproform.hxx b/sc/source/filter/inc/qproform.hxx
index 35622618e260..cecb70d6ec55 100644
--- a/sc/source/filter/inc/qproform.hxx
+++ b/sc/source/filter/inc/qproform.hxx
@@ -58,7 +58,7 @@ private:
 public:
     static const size_t nBufSize = 256;
     QProToSc( SvStream &aStr, svl::SharedStringPool& rSPool, const ScAddress& rRefPos );
-    ConvErr Convert( const ScTokenArray*& pArray );
+    ConvErr Convert( std::unique_ptr<ScTokenArray>& pArray );
     void DoFunc( DefTokenId eOc, sal_uInt16 nArgs, const sal_Char* pExtString );
     void ReadSRD( ScSingleRefData& rR, sal_Int8 nPage, sal_Int8 nCol, sal_uInt16 rRel );
     void IncToken( TokenId &aParam );
diff --git a/sc/source/filter/inc/tokstack.hxx b/sc/source/filter/inc/tokstack.hxx
index a0dd2f80fba0..6b0ce783d4fc 100644
--- a/sc/source/filter/inc/tokstack.hxx
+++ b/sc/source/filter/inc/tokstack.hxx
@@ -209,7 +209,6 @@ private:
 #ifdef DBG_UTIL
         sal_uInt16                      m_nRek; // recursion counter
 #endif
-        std::unique_ptr<ScTokenArray>   pScToken;   // Token array
 
         bool                        GrowTripel( sal_uInt16 nByMin );
         bool                        GrowId();
@@ -222,8 +221,8 @@ private:
                                         nElementCurrent+1.
                                      */
         bool                        CheckElementOrGrow();
-        bool                        GetElement( const sal_uInt16 nId );
-        bool                        GetElementRek( const sal_uInt16 nId );
+        bool                        GetElement( const sal_uInt16 nId, ScTokenArray* pScToken );
+        bool                        GetElementRek( const sal_uInt16 nId, ScTokenArray* pScToken );
         void                        ClearMatrix();
 public:
     TokenPool( svl::SharedStringPool& rSPool );
@@ -252,7 +251,7 @@ public:
         const TokenId               StoreExtRef( sal_uInt16 nFileId, const OUString& rTabName, const ScSingleRefData& rRef );
         const TokenId               StoreExtRef( sal_uInt16 nFileId, const OUString& rTabName, const ScComplexRefData& rRef );
 
-        inline const ScTokenArray*  operator []( const TokenId& rId );
+        std::unique_ptr<ScTokenArray> GetTokenArray( const TokenId& rId );
         void                        Reset();
         bool                        IsSingleOp( const TokenId& rId, const DefTokenId eId ) const;
         const OUString*             GetExternal( const TokenId& rId ) const;
@@ -412,19 +411,19 @@ inline const TokenId TokenPool::Store()
     return nId;
 }
 
-const inline ScTokenArray* TokenPool::operator []( const TokenId& rId )
+inline std::unique_ptr<ScTokenArray> TokenPool::GetTokenArray( const TokenId& rId )
 {
-    pScToken->Clear();
+    std::unique_ptr<ScTokenArray> pScToken( new ScTokenArray );
 
     if( rId )
     {//...only if rId > 0!
 #ifdef DBG_UTIL
         m_nRek = 0;
 #endif
-        GetElement( static_cast<sal_uInt16>(rId) - 1 );
+        GetElement( static_cast<sal_uInt16>(rId) - 1, pScToken.get());
     }
 
-    return pScToken.get();
+    return pScToken;
 }
 
 
diff --git a/sc/source/filter/inc/xiformula.hxx b/sc/source/filter/inc/xiformula.hxx
index a24c008d96fb..7af2dd9d3132 100644
--- a/sc/source/filter/inc/xiformula.hxx
+++ b/sc/source/filter/inc/xiformula.hxx
@@ -43,12 +43,9 @@ public:
                             const XclTokenArray& rXclTokArr, XclImpStream& rStrm );
 
     /**
-     * Creates a formula token array from the Excel token array.  Note that
-     * the caller must create a copy of the token array instance returned by
-     * this function if the caller needs to persistently store the array,
-     * because the pointer points to an array instance on the stack.
+     * Creates a formula token array from the Excel token array.
      */
-    const ScTokenArray* CreateFormula( XclFormulaType eType, const XclTokenArray& rXclTokArr );
+    std::unique_ptr<ScTokenArray> CreateFormula( XclFormulaType eType, const XclTokenArray& rXclTokArr );
 
 private:
     typedef std::shared_ptr< XclImpFmlaCompImpl > XclImpFmlaCompImplRef;
diff --git a/sc/source/filter/lotus/lotform.cxx b/sc/source/filter/lotus/lotform.cxx
index 4371a5587798..f25fc57e1562 100644
--- a/sc/source/filter/lotus/lotform.cxx
+++ b/sc/source/filter/lotus/lotform.cxx
@@ -384,7 +384,7 @@ LotusToSc::LotusToSc(LotusContext &rContext, SvStream &rStream, svl::SharedStrin
 typedef FUNC_TYPE ( FuncType1 ) ( sal_uInt8 );
 typedef DefTokenId ( FuncType2 ) ( sal_uInt8 );
 
-void LotusToSc::Convert( const ScTokenArray*& rpErg, sal_Int32& rRest )
+void LotusToSc::Convert( std::unique_ptr<ScTokenArray>& rpErg, sal_Int32& rRest )
 {
     sal_uInt8               nOc;
     sal_uInt8               nCnt;
@@ -438,7 +438,7 @@ void LotusToSc::Convert( const ScTokenArray*& rpErg, sal_Int32& rRest )
 
         if( nBytesLeft < 0 )
         {
-            rpErg = aPool[ aStack.Get() ];
+            rpErg = aPool.GetTokenArray( aStack.Get());
             return;
         }
 
@@ -659,7 +659,7 @@ void LotusToSc::Convert( const ScTokenArray*& rpErg, sal_Int32& rRest )
         }
     }
 
-    rpErg = aPool[ aStack.Get() ];
+    rpErg = aPool.GetTokenArray( aStack.Get());
 
     SAL_WARN_IF( nBytesLeft < 0, "sc.filter", "*LotusToSc::Convert(): processed too much!");
     SAL_WARN_IF( nBytesLeft > 0, "sc.filter", "*LotusToSc::Convert(): what happens with the rest?" );
diff --git a/sc/source/filter/lotus/lotimpop.cxx b/sc/source/filter/lotus/lotimpop.cxx
index f93c965efa42..abf7fc36fc69 100644
--- a/sc/source/filter/lotus/lotimpop.cxx
+++ b/sc/source/filter/lotus/lotimpop.cxx
@@ -270,7 +270,7 @@ void ImportLotus::Formulacell( sal_uInt16 n )
 
     n -= std::min<sal_uInt16>(n, 14);
 
-    const ScTokenArray* pErg;
+    std::unique_ptr<ScTokenArray> pErg;
     sal_Int32 nRest = n;
 
     aConv.Reset( aAddr );
@@ -279,7 +279,7 @@ void ImportLotus::Formulacell( sal_uInt16 n )
     if (!aConv.good())
         return;
 
-    ScFormulaCell* pCell = pErg ? new ScFormulaCell(pD, aAddr, *pErg) : new ScFormulaCell(pD, aAddr);
+    ScFormulaCell* pCell = pErg ? new ScFormulaCell(pD, aAddr, pErg.release()) : new ScFormulaCell(pD, aAddr);
     pCell->AddRecalcMode( ScRecalcMode::ONLOAD_ONCE );
     pD->EnsureTable(aAddr.Tab());
     pD->SetFormulaCell(aAddr, pCell);
diff --git a/sc/source/filter/lotus/op.cxx b/sc/source/filter/lotus/op.cxx
index 6fca43504b8d..1099aa870232 100644
--- a/sc/source/filter/lotus/op.cxx
+++ b/sc/source/filter/lotus/op.cxx
@@ -144,7 +144,7 @@ void OP_Formula(LotusContext &rContext, SvStream& r, sal_uInt16 /*n*/)
     SCCOL nCol(static_cast<SCCOL>(nTmpCol));
     SCROW nRow(static_cast<SCROW>(nTmpRow));
 
-    const ScTokenArray* pResult;
+    std::unique_ptr<ScTokenArray> pResult;
     sal_Int32 nBytesLeft = nFormulaSize;
     ScAddress aAddress(nCol, nRow, 0);
 
@@ -157,7 +157,7 @@ void OP_Formula(LotusContext &rContext, SvStream& r, sal_uInt16 /*n*/)
 
     if (ValidColRow(nCol, nRow))
     {
-        ScFormulaCell* pCell = new ScFormulaCell(rContext.pLotusRoot->pDoc, aAddress, *pResult);
+        ScFormulaCell* pCell = new ScFormulaCell(rContext.pLotusRoot->pDoc, aAddress, pResult.release());
         pCell->AddRecalcMode( ScRecalcMode::ONLOAD_ONCE );
         rContext.pDoc->EnsureTable(0);
         rContext.pDoc->SetFormulaCell(ScAddress(nCol, nRow, 0), pCell);
@@ -402,7 +402,7 @@ void OP_Formula123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
     SCROW nRow(static_cast<SCROW>(nTmpRow));
     r.SeekRel( 8 );    // skip Result
 
-    const ScTokenArray* pResult;
+    std::unique_ptr<ScTokenArray> pResult;
     sal_Int32 nBytesLeft = (n > 12) ? n - 12 : 0;
     ScAddress aAddress( nCol, nRow, nTab );
 
@@ -415,7 +415,7 @@ void OP_Formula123(LotusContext& rContext, SvStream& r, sal_uInt16 n)
 
     if (ValidColRow(nCol, nRow) && nTab <= rContext.pDoc->GetMaxTableNumber())
     {
-        ScFormulaCell* pCell = new ScFormulaCell(rContext.pLotusRoot->pDoc, aAddress, *pResult);
+        ScFormulaCell* pCell = new ScFormulaCell(rContext.pLotusRoot->pDoc, aAddress, pResult.release());
         pCell->AddRecalcMode( ScRecalcMode::ONLOAD_ONCE );
         rContext.pDoc->EnsureTable(nTab);
         rContext.pDoc->SetFormulaCell(ScAddress(nCol,nRow,nTab), pCell);
diff --git a/sc/source/filter/qpro/qpro.cxx b/sc/source/filter/qpro/qpro.cxx
index 28cbf788c5be..c6bca203eb21 100644
--- a/sc/source/filter/qpro/qpro.cxx
+++ b/sc/source/filter/qpro/qpro.cxx
@@ -111,14 +111,14 @@ ErrCode ScQProReader::readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pSty
                     break;
                 }
                 ScAddress aAddr( nCol, nRow, nTab );
-                const ScTokenArray *pArray;
+                std::unique_ptr<ScTokenArray> pArray;
 
                 QProToSc aConv(*mpStream, pDoc->GetSharedStringPool(), aAddr);
                 if (ConvErr::OK != aConv.Convert( pArray ))
                     eRet = SCERR_IMPORT_FORMAT;
                 else
                 {
-                    ScFormulaCell* pFormula = new ScFormulaCell(pDoc, aAddr, *pArray);
+                    ScFormulaCell* pFormula = new ScFormulaCell(pDoc, aAddr, pArray.release());
                     nStyle = nStyle >> 3;
                     pFormula->AddRecalcMode( ScRecalcMode::ONLOAD_ONCE );
                     pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
diff --git a/sc/source/filter/qpro/qproform.cxx b/sc/source/filter/qpro/qproform.cxx
index a3a68c649480..0382228f3ecc 100644
--- a/sc/source/filter/qpro/qproform.cxx
+++ b/sc/source/filter/qpro/qproform.cxx
@@ -193,7 +193,7 @@ do { \
         break;          /* switch */ \
     }
 
-ConvErr QProToSc::Convert( const ScTokenArray*& pArray )
+ConvErr QProToSc::Convert( std::unique_ptr<ScTokenArray>& pArray )
 {
     sal_uInt8 nFmla[ nBufSize ], nArg;
     sal_uInt8 nArgArray[ nBufSize ] = {0};
@@ -392,7 +392,7 @@ ConvErr QProToSc::Convert( const ScTokenArray*& pArray )
         }
         i++;
     }
-    pArray = aPool[ aStack.Get() ];
+    pArray = aPool.GetTokenArray( aStack.Get());
     return eRet;
 }
 
diff --git a/sc/source/filter/xcl97/XclImpChangeTrack.cxx b/sc/source/filter/xcl97/XclImpChangeTrack.cxx
index f212b231c6dd..5ad6ccca9559 100644
--- a/sc/source/filter/xcl97/XclImpChangeTrack.cxx
+++ b/sc/source/filter/xcl97/XclImpChangeTrack.cxx
@@ -179,7 +179,7 @@ void XclImpChangeTrack::Read3DTabRefInfo( SCTAB& rFirstTab, SCTAB& rLastTab, Exc
     }
 }
 
-void XclImpChangeTrack::ReadFormula( ScTokenArray*& rpTokenArray, const ScAddress& rPosition )
+void XclImpChangeTrack::ReadFormula( std::unique_ptr<ScTokenArray>& rpTokenArray, const ScAddress& rPosition )
 {
     sal_uInt16 nFmlSize = pStrm->ReaduInt16();
 
@@ -208,10 +208,10 @@ void XclImpChangeTrack::ReadFormula( ScTokenArray*& rpTokenArray, const ScAddres
     XclImpChTrFmlConverter aFmlConv( GetRoot(), *this );
 
     // read the formula, 3D tab refs from extended data
-    const ScTokenArray* pArray = nullptr;
+    std::unique_ptr<ScTokenArray> pArray;
     aFmlConv.Reset( rPosition );
     bool bOK = (aFmlConv.Convert( pArray, aFmlaStrm, nFmlSize, false ) == ConvErr::OK);   // JEG : Check This
-    rpTokenArray = (bOK && pArray) ? new ScTokenArray( *pArray ) : nullptr;
+    rpTokenArray = (bOK && pArray) ? std::move( pArray ) : nullptr;
     pStrm->Ignore( 1 );
 }
 
@@ -267,14 +267,13 @@ void XclImpChangeTrack::ReadCell(
         break;
         case EXC_CHTR_TYPE_FORMULA:
         {
-            ScTokenArray* pTokenArray = nullptr;
+            std::unique_ptr<ScTokenArray> pTokenArray;
             ReadFormula( pTokenArray, rPosition );
             if( pStrm->IsValid() && pTokenArray )
             {
                 rCell.meType = CELLTYPE_FORMULA;
-                rCell.mpFormula = new ScFormulaCell(&GetDocRef(), rPosition, *pTokenArray);
+                rCell.mpFormula = new ScFormulaCell(&GetDocRef(), rPosition, pTokenArray.release());
             }
-            delete pTokenArray;
         }
         break;
         default:


More information about the Libreoffice-commits mailing list