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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Jan 29 10:03:55 UTC 2019


 sc/source/filter/inc/lotrange.hxx |    4 ++--
 sc/source/filter/lotus/op.cxx     |   20 ++++++++++----------
 sc/source/filter/lotus/tool.cxx   |   25 ++++++++++++-------------
 3 files changed, 24 insertions(+), 25 deletions(-)

New commits:
commit aa64dbfb76bde6cc29c3569cc9e31d949ce22787
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Jan 29 09:27:06 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Jan 29 11:03:29 2019 +0100

    use unique_ptr in LotusRangeList
    
    Change-Id: Ie99b3a4d6a311b2f5140a00fddbbd53801b8cfb3
    Reviewed-on: https://gerrit.libreoffice.org/67045
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/filter/inc/lotrange.hxx b/sc/source/filter/inc/lotrange.hxx
index 96dad2ac9099..4fbbd12a9665 100644
--- a/sc/source/filter/inc/lotrange.hxx
+++ b/sc/source/filter/inc/lotrange.hxx
@@ -89,7 +89,7 @@ class LotusRangeList
 private:
     LR_ID               nIdCnt;
     ScComplexRefData    aComplRef;
-    std::vector<LotusRange*> maRanges;
+    std::vector<std::unique_ptr<LotusRange>> maRanges;
 
 public:
     LotusRangeList();
@@ -97,7 +97,7 @@ public:
     inline sal_uInt16       GetIndex( SCCOL nCol, SCROW nRow );
     inline sal_uInt16       GetIndex( SCCOL nColS, SCROW nRowS, SCCOL nColE, SCROW nRowE );
     sal_uInt16              GetIndex( const LotusRange& );
-    void                Append( LotusRange* pLR );
+    void                Append( std::unique_ptr<LotusRange> pLR );
 };
 
 inline LR_ID LotusRangeList::GetIndex( SCCOL nCol, SCROW nRow )
diff --git a/sc/source/filter/lotus/op.cxx b/sc/source/filter/lotus/op.cxx
index 1cd43ef1b376..ae7f2d0e9050 100644
--- a/sc/source/filter/lotus/op.cxx
+++ b/sc/source/filter/lotus/op.cxx
@@ -201,13 +201,13 @@ void OP_NamedRange(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
 
     if (ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd))
     {
-        LotusRange*      pRange;
+        std::unique_ptr<LotusRange> pRange;
 
         if( nColSt == nColEnd && nRowSt == nRowEnd )
-            pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
+            pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) ));
         else
-            pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
-                    static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
+            pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
+                    static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) ));
 
         sal_Char cBuf[sizeof(cBuffer)+1];
         if( rtl::isAsciiDigit( static_cast<unsigned char>(*cBuffer) ) )
@@ -222,7 +222,7 @@ void OP_NamedRange(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
 
         aTmp = ScfTools::ConvertToScDefinedName( aTmp );
 
-        rContext.pLotusRoot->maRangeNames.Append( pRange );
+        rContext.pLotusRoot->maRangeNames.Append( std::move(pRange) );
     }
 }
 
@@ -240,13 +240,13 @@ void OP_SymphNamedRange(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
 
     if (ValidColRow( static_cast<SCCOL>(nColSt), nRowSt) && ValidColRow( static_cast<SCCOL>(nColEnd), nRowEnd))
     {
-        LotusRange*      pRange;
+        std::unique_ptr<LotusRange> pRange;
 
         if( nType )
-            pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) );
+            pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt) ));
         else
-            pRange = new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
-                    static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) );
+            pRange.reset(new LotusRange( static_cast<SCCOL> (nColSt), static_cast<SCROW> (nRowSt),
+                    static_cast<SCCOL> (nColEnd), static_cast<SCROW> (nRowEnd) ));
 
         sal_Char cBuf[sizeof(cBuffer)+1];
         if( rtl::isAsciiDigit( static_cast<unsigned char>(*cBuffer) ) )
@@ -260,7 +260,7 @@ void OP_SymphNamedRange(LotusContext& rContext, SvStream& r, sal_uInt16 /*n*/)
         OUString  aTmp( cBuf, strlen(cBuf), rContext.pLotusRoot->eCharsetQ );
         aTmp = ScfTools::ConvertToScDefinedName( aTmp );
 
-        rContext.pLotusRoot->maRangeNames.Append( pRange );
+        rContext.pLotusRoot->maRangeNames.Append( std::move(pRange) );
     }
 }
 
diff --git a/sc/source/filter/lotus/tool.cxx b/sc/source/filter/lotus/tool.cxx
index 11063f0c2bd0..dabbd05dcd03 100644
--- a/sc/source/filter/lotus/tool.cxx
+++ b/sc/source/filter/lotus/tool.cxx
@@ -386,43 +386,42 @@ LotusRangeList::LotusRangeList()
 
 LotusRangeList::~LotusRangeList ()
 {
-    for (const auto& rpRange : maRanges)
-        delete rpRange;
 }
 
 LR_ID LotusRangeList::GetIndex( const LotusRange &rRef )
 {
-    std::vector<LotusRange*>::iterator pIter = std::find_if(maRanges.begin(), maRanges.end(),
-        [&rRef](const LotusRange* pRange) { return rRef == *pRange; });
+    auto pIter = std::find_if(maRanges.begin(), maRanges.end(),
+        [&rRef](const std::unique_ptr<LotusRange>& pRange) { return rRef == *pRange; });
     if (pIter != maRanges.end())
         return (*pIter)->nId;
 
     return ID_FAIL;
 }
 
-void LotusRangeList::Append( LotusRange* pLR )
+void LotusRangeList::Append( std::unique_ptr<LotusRange> pLR )
 {
-    SAL_WARN_IF( !pLR, "sc.filter", "*LotusRangeList::Append(): no pointer!" );
-    maRanges.push_back(pLR);
+    assert( pLR );
+    auto pLRTmp = pLR.get();
+    maRanges.push_back(std::move(pLR));
 
     ScTokenArray    aTokArray;
 
     ScSingleRefData*    pSingRef = &aComplRef.Ref1;
 
-    pSingRef->SetAbsCol(pLR->nColStart);
-    pSingRef->SetAbsRow(pLR->nRowStart);
+    pSingRef->SetAbsCol(pLRTmp->nColStart);
+    pSingRef->SetAbsRow(pLRTmp->nRowStart);
 
-    if( pLR->IsSingle() )
+    if( pLRTmp->IsSingle() )
         aTokArray.AddSingleReference( *pSingRef );
     else
     {
         pSingRef = &aComplRef.Ref2;
-        pSingRef->SetAbsCol(pLR->nColEnd);
-        pSingRef->SetAbsRow(pLR->nRowEnd);
+        pSingRef->SetAbsCol(pLRTmp->nColEnd);
+        pSingRef->SetAbsRow(pLRTmp->nRowEnd);
         aTokArray.AddDoubleReference( aComplRef );
     }
 
-    pLR->SetId( nIdCnt );
+    pLRTmp->SetId( nIdCnt );
 
     nIdCnt++;
 }


More information about the Libreoffice-commits mailing list