sc/inc/queryentry.hxx              |    4 ++--
 sc/source/core/inc/jumpmatrix.hxx  |    6 +++---
 sc/source/core/tool/interpr1.cxx   |   15 ++++++---------
 sc/source/core/tool/interpr4.cxx   |    6 +++---
 sc/source/core/tool/jumpmatrix.cxx |   17 ++++-------------
 sc/source/core/tool/queryentry.cxx |   22 ++++++++--------------
 6 files changed, 26 insertions(+), 44 deletions(-)

New commits:
commit 9d037cb837d74708358168333a0b457952de23a6
Author: Noel Grandin <noel.gran...@collabora.co.uk>
Date:   Tue Apr 3 14:05:20 2018 +0200

    loplugin:useuniqueptr in ScJumpMatrix
    
    Change-Id: Ia8461773bdb2290690616b291356edd3a9ea4f35
    Reviewed-on: https://gerrit.libreoffice.org/52341
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/core/inc/jumpmatrix.hxx 
b/sc/source/core/inc/jumpmatrix.hxx
index 084f5a91f4bb..c4a0b5784896 100644
--- a/sc/source/core/inc/jumpmatrix.hxx
+++ b/sc/source/core/inc/jumpmatrix.hxx
@@ -60,7 +60,7 @@ class ScJumpMatrix
     std::vector<ScJumpMatrixEntry> mvJump;      // the jumps
     ScMatrixRef         pMat;       // the results
     ScRefList           mvRefList;  // array of references result, if any
-    ScTokenVec*         pParams;    // parameter stack
+    ScTokenVec          mvParams;    // parameter stack
     SCSIZE              nCols;
     SCSIZE              nRows;
     SCSIZE              nCurCol;
@@ -103,8 +103,8 @@ public:
     void SetJump( SCSIZE nCol, SCSIZE nRow, double fBool, short nStart, short 
nNext );
     void GetJump( SCSIZE nCol, SCSIZE nRow, double& rBool, short& rStart, 
short& rNext, short& rStop ) const;
     void SetAllJumps( double fBool, short nStart, short nNext, short nStop = 
SHRT_MAX );
-    void SetJumpParameters( ScTokenVec* p );
-    const ScTokenVec* GetJumpParameters() const { return pParams;}
+    void SetJumpParameters( ScTokenVec&& p );
+    const ScTokenVec & GetJumpParameters() const { return mvParams;}
     bool HasResultMatrix() const;
     ScMatrix* GetResultMatrix();        ///< also applies pending buffered 
values
     void GetPos( SCSIZE& rCol, SCSIZE& rRow ) const;
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 06fc60b8a18e..51a2a422abfc 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -786,16 +786,13 @@ bool ScInterpreter::JumpMatrix( short nStackLevel )
         }
         if ( bCont && nStart != nNext )
         {
-            const ScTokenVec* pParams = pJumpMatrix->GetJumpParameters();
-            if ( pParams )
+            const ScTokenVec & rParams = pJumpMatrix->GetJumpParameters();
+            for ( auto const & i : rParams )
             {
-                for ( ScTokenVec::const_iterator i = pParams->begin(); i != 
pParams->end(); ++i )
-                {
-                    // This is not the current state of the interpreter, so
-                    // push without error, and elements' errors are coded into
-                    // double.
-                    PushWithoutError( *(*i));
-                }
+                // This is not the current state of the interpreter, so
+                // push without error, and elements' errors are coded into
+                // double.
+                PushWithoutError(*i);
             }
             aCode.Jump( nStart, nNext, nStop );
         }
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index e631ffaf9139..d28d8138a88a 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -1576,15 +1576,15 @@ bool ScInterpreter::ConvertMatrixParameters()
             std::unique_ptr<ScJumpMatrix> pJumpMat( new ScJumpMatrix( 
pCur->GetOpCode(), nJumpCols, nJumpRows));
             pJumpMat->SetAllJumps( 1.0, nStart, nNext, nStop);
             // pop parameters and store in ScJumpMatrix, push in JumpMatrix()
-            ScTokenVec* pParams = new ScTokenVec( nParams);
+            ScTokenVec aParams(nParams);
             for ( sal_uInt16 i=1; i <= nParams && sp > 0; ++i )
             {
                 const FormulaToken* p = pStack[ --sp ];
                 p->IncRef();
                 // store in reverse order such that a push may simply iterate
-                (*pParams)[ nParams - i ] = p;
+                aParams[ nParams - i ] = p;
             }
-            pJumpMat->SetJumpParameters( pParams);
+            pJumpMat->SetJumpParameters( std::move(aParams) );
             xNew = new ScJumpMatrixToken( std::move(pJumpMat) );
             GetTokenMatrixMap().emplace(pCur, xNew);
         }
diff --git a/sc/source/core/tool/jumpmatrix.cxx 
b/sc/source/core/tool/jumpmatrix.cxx
index ed71c69c1a20..c3153fd5ac3e 100644
--- a/sc/source/core/tool/jumpmatrix.cxx
+++ b/sc/source/core/tool/jumpmatrix.cxx
@@ -30,7 +30,6 @@ const SCSIZE kBufferThreshold = 128;
 ScJumpMatrix::ScJumpMatrix( OpCode eOp, SCSIZE nColsP, SCSIZE nRowsP )
     : mvJump(nColsP * nRowsP)
     , pMat(new ScFullMatrix(nColsP, nRowsP))
-    , pParams(nullptr)
     , nCols(nColsP)
     , nRows(nRowsP)
     , nCurCol(0)
@@ -53,16 +52,8 @@ ScJumpMatrix::ScJumpMatrix( OpCode eOp, SCSIZE nColsP, 
SCSIZE nRowsP )
 
 ScJumpMatrix::~ScJumpMatrix()
 {
-    if (pParams)
-    {
-        for (ScTokenVec::iterator i =
-             pParams->begin(); i !=
-                 pParams->end(); ++i)
-        {
-            (*i)->DecRef();
-        }
-        delete pParams;
-    }
+    for (auto & i : mvParams)
+        i->DecRef();
 }
 
 void ScJumpMatrix::GetDimensions(SCSIZE& rCols, SCSIZE& rRows) const
@@ -107,9 +98,9 @@ void ScJumpMatrix::SetAllJumps(double fBool, short nStart, 
short nNext, short nS
     }
 }
 
-void ScJumpMatrix::SetJumpParameters(ScTokenVec* p)
+void ScJumpMatrix::SetJumpParameters(ScTokenVec&& p)
 {
-    pParams = p;
+    mvParams = std::move(p);
 }
 
 void ScJumpMatrix::GetPos(SCSIZE& rCol, SCSIZE& rRow) const
commit b7f6dc5957ac615f38b26d6e0147306cac1c3d7b
Author: Noel Grandin <noel.gran...@collabora.co.uk>
Date:   Tue Apr 3 12:55:24 2018 +0200

    loplugin:useuniqueptr in ScQueryEntry
    
    Change-Id: Ifcae24f5446410ae56d1a767953939e73ff5d72d
    Reviewed-on: https://gerrit.libreoffice.org/52340
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/queryentry.hxx b/sc/inc/queryentry.hxx
index ab1a36fc5d9e..fc08c58b7a49 100644
--- a/sc/inc/queryentry.hxx
+++ b/sc/inc/queryentry.hxx
@@ -51,8 +51,8 @@ struct SC_DLLPUBLIC ScQueryEntry
     SCCOLROW        nField;
     ScQueryOp       eOp;
     ScQueryConnect  eConnect;
-    mutable utl::SearchParam* pSearchParam;       ///< if Wildcard or RegExp, 
not saved
-    mutable utl::TextSearch*  pSearchText;        ///< if Wildcard or RegExp, 
not saved
+    mutable std::unique_ptr<utl::SearchParam> pSearchParam;       ///< if 
Wildcard or RegExp, not saved
+    mutable std::unique_ptr<utl::TextSearch>  pSearchText;        ///< if 
Wildcard or RegExp, not saved
 
     ScQueryEntry();
     ScQueryEntry(const ScQueryEntry& r);
diff --git a/sc/source/core/tool/queryentry.cxx 
b/sc/source/core/tool/queryentry.cxx
index e794532b285a..f08783927fc8 100644
--- a/sc/source/core/tool/queryentry.cxx
+++ b/sc/source/core/tool/queryentry.cxx
@@ -59,8 +59,6 @@ ScQueryEntry::ScQueryEntry(const ScQueryEntry& r) :
 
 ScQueryEntry::~ScQueryEntry()
 {
-    delete pSearchParam;
-    delete pSearchText;
 }
 
 ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r )
@@ -71,10 +69,8 @@ ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r 
)
     nField          = r.nField;
     maQueryItems  = r.maQueryItems;
 
-    delete pSearchParam;
-    delete pSearchText;
-    pSearchParam    = nullptr;
-    pSearchText     = nullptr;
+    pSearchParam.reset();
+    pSearchText.reset();
 
     return *this;
 }
@@ -148,10 +144,8 @@ void ScQueryEntry::Clear()
     maQueryItems.clear();
     maQueryItems.emplace_back();
 
-    delete pSearchParam;
-    delete pSearchText;
-    pSearchParam    = nullptr;
-    pSearchText     = nullptr;
+    pSearchParam.reset();
+    pSearchText.reset();
 }
 
 bool ScQueryEntry::operator==( const ScQueryEntry& r ) const
@@ -170,11 +164,11 @@ utl::TextSearch* ScQueryEntry::GetSearchTextPtr( 
utl::SearchParam::SearchType eS
     if ( !pSearchParam )
     {
         OUString aStr = maQueryItems[0].maString.getString();
-        pSearchParam = new utl::SearchParam(
-            aStr, eSearchType, bCaseSens, '~', bWildMatchSel);
-        pSearchText = new utl::TextSearch( *pSearchParam, 
*ScGlobal::pCharClass );
+        pSearchParam.reset(new utl::SearchParam(
+            aStr, eSearchType, bCaseSens, '~', bWildMatchSel));
+        pSearchText.reset(new utl::TextSearch( *pSearchParam, 
*ScGlobal::pCharClass ));
     }
-    return pSearchText;
+    return pSearchText.get();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to