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

Noel Grandin noel.grandin at collabora.co.uk
Thu Jul 12 09:02:55 UTC 2018


 sc/source/filter/html/htmlpars.cxx |   49 ++++++++++++++++---------------------
 sc/source/filter/inc/htmlpars.hxx  |    8 +++---
 2 files changed, 26 insertions(+), 31 deletions(-)

New commits:
commit 510033783a9921eef507d424fc5adf6e2696bc4a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Jul 11 12:46:41 2018 +0200

    loplugin:useuniqueptr in ScHTMLLayoutParser
    
    bitfields and make_unique don't play nice together, so bFirstRow
    had to become a regular bool field.
    
    Change-Id: I990a0ddcbbef5e826fbe26736e68ebce55cebb4c
    Reviewed-on: https://gerrit.libreoffice.org/57303
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx
index 64529b39c9d7..04ba99cdaef0 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -214,12 +214,12 @@ ScHTMLLayoutParser::ScHTMLLayoutParser(
         nColOffset(0),
         nColOffsetStart(0),
         nOffsetTolerance( SC_HTML_OFFSET_TOLERANCE_SMALL ),
-        bTabInTabCell( false ),
         bFirstRow( true ),
+        bTabInTabCell( false ),
         bInCell( false ),
         bInTitle( false )
 {
-    MakeColNoRef( pLocalColOffset, 0, 0, 0, 0 );
+    MakeColNoRef( pLocalColOffset.get(), 0, 0, 0, 0 );
     MakeColNoRef( &maColOffset, 0, 0, 0, 0 );
 }
 
@@ -227,18 +227,17 @@ ScHTMLLayoutParser::~ScHTMLLayoutParser()
 {
     while ( !aTableStack.empty() )
     {
-        ScHTMLTableStackEntry* pS = aTableStack.top();
-        aTableStack.pop();
-        if ( pS->pLocalColOffset != pLocalColOffset )
+        ScHTMLTableStackEntry* pS = aTableStack.top().get();
+        if ( pS->pLocalColOffset != pLocalColOffset.get() )
             delete pS->pLocalColOffset;
-        delete pS;
+        aTableStack.pop();
     }
-    delete pLocalColOffset;
+    pLocalColOffset.reset();
     if ( pTables )
     {
         for( OuterMap::const_iterator it = pTables->begin(); it != pTables->end(); ++it)
             delete it->second;
-        delete pTables;
+        pTables.reset();
     }
 }
 
@@ -646,7 +645,7 @@ void ScHTMLLayoutParser::SetWidths()
         pLocalColOffset->clear();
         for ( nCol = 0; nCol <= nColsPerRow; ++nCol, nOff = nOff + nWidth )
         {
-            MakeColNoRef( pLocalColOffset, nOff, 0, 0, 0 );
+            MakeColNoRef( pLocalColOffset.get(), nOff, 0, 0, 0 );
         }
         nTableWidth = static_cast<sal_uInt16>(pLocalColOffset->back() - pLocalColOffset->front());
         for ( size_t i = nFirstTableCell, nListSize = maList.size(); i < nListSize; ++i )
@@ -736,7 +735,7 @@ void ScHTMLLayoutParser::SetWidths()
             pLocalColOffset->clear();
             for ( nCol = 0; nCol <= nColsPerRow; nCol++ )
             {
-                MakeColNoRef( pLocalColOffset, pOffsets[nCol], 0, 0, 0 );
+                MakeColNoRef( pLocalColOffset.get(), pOffsets[nCol], 0, 0, 0 );
             }
             nTableWidth = pOffsets[nColsPerRow] - pOffsets[0];
 
@@ -800,7 +799,7 @@ void ScHTMLLayoutParser::Colonize( ScEEParseEntry* pE )
     }
     pE->nOffset = nColOffset;
     sal_uInt16 nWidth = GetWidth( pE );
-    MakeCol( pLocalColOffset, pE->nOffset, nWidth, nOffsetTolerance, nOffsetTolerance );
+    MakeCol( pLocalColOffset.get(), pE->nOffset, nWidth, nOffsetTolerance, nOffsetTolerance );
     if ( pE->nWidth )
         pE->nWidth = nWidth;
     nColOffset = pE->nOffset + nWidth;
@@ -1032,8 +1031,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo )
     {   // Table in Table
         sal_uInt16 nTmpColOffset = nColOffset; // Will be changed in Colonize()
         Colonize(mxActEntry.get());
-        aTableStack.push( new ScHTMLTableStackEntry(
-            mxActEntry, xLockedList, pLocalColOffset, nFirstTableCell,
+        aTableStack.push( o3tl::make_unique<ScHTMLTableStackEntry>(
+            mxActEntry, xLockedList, pLocalColOffset.get(), nFirstTableCell,
             nRowCnt, nColCntStart, nMaxCol, nTable,
             nTableWidth, nColOffset, nColOffsetStart,
             bFirstRow ) );
@@ -1088,8 +1087,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo )
             CloseEntry( pInfo );
             NextRow( pInfo );
         }
-        aTableStack.push( new ScHTMLTableStackEntry(
-            mxActEntry, xLockedList, pLocalColOffset, nFirstTableCell,
+        aTableStack.push( o3tl::make_unique<ScHTMLTableStackEntry>(
+            mxActEntry, xLockedList, pLocalColOffset.get(), nFirstTableCell,
             nRowCnt, nColCntStart, nMaxCol, nTable,
             nTableWidth, nColOffset, nColOffsetStart,
             bFirstRow ) );
@@ -1122,8 +1121,8 @@ void ScHTMLLayoutParser::TableOn( HtmlImportInfo* pInfo )
     bFirstRow = true;
     nFirstTableCell = maList.size();
 
-    pLocalColOffset = new ScHTMLColOffset;
-    MakeColNoRef( pLocalColOffset, nColOffsetStart, 0, 0, 0 );
+    pLocalColOffset.reset( new ScHTMLColOffset );
+    MakeColNoRef( pLocalColOffset.get(), nColOffsetStart, 0, 0, 0 );
 }
 
 void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
@@ -1141,7 +1140,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
     {   // Table in Table done
         if ( !aTableStack.empty() )
         {
-            ScHTMLTableStackEntry* pS = aTableStack.top();
+            std::unique_ptr<ScHTMLTableStackEntry> pS = std::move(aTableStack.top());
             aTableStack.pop();
 
             auto& pE = pS->xCellEntry;
@@ -1151,7 +1150,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
                 SCROW nRow = pS->nRowCnt;
                 sal_uInt16 nTab = pS->nTable;
                 if ( !pTables )
-                    pTables = new OuterMap;
+                    pTables.reset( new OuterMap );
                 // Height of outer table
                 OuterMap::const_iterator it = pTables->find( nTab );
                 InnerMap* pTab1;
@@ -1258,12 +1257,10 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
             nColOffsetStart = pS->nColOffsetStart;
             bFirstRow = pS->bFirstRow;
             xLockedList = pS->xLockedList;
-            delete pLocalColOffset;
-            pLocalColOffset = pS->pLocalColOffset;
+            pLocalColOffset.reset( pS->pLocalColOffset );
             // mxActEntry is kept around if a table is started in the same row
             // (anything's possible in HTML); will be deleted by CloseEntry
             mxActEntry = pE;
-            delete pS;
         }
         bTabInTabCell = true;
         bInCell = true;
@@ -1275,11 +1272,9 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* pInfo )
         nTable = 0;
         if ( !aTableStack.empty() )
         {
-            ScHTMLTableStackEntry* pS = aTableStack.top();
+            std::unique_ptr<ScHTMLTableStackEntry> pS = std::move(aTableStack.top());
             aTableStack.pop();
-            delete pLocalColOffset;
-            pLocalColOffset = pS->pLocalColOffset;
-            delete pS;
+            pLocalColOffset.reset( pS->pLocalColOffset );
         }
     }
 }
@@ -1385,7 +1380,7 @@ void ScHTMLLayoutParser::ColOn( HtmlImportInfo* pInfo )
         if( rOption.GetToken() == HtmlOptionId::WIDTH )
         {
             sal_uInt16 nVal = GetWidthPixel( rOption );
-            MakeCol( pLocalColOffset, nColOffset, nVal, 0, 0 );
+            MakeCol( pLocalColOffset.get(), nColOffset, nVal, 0, 0 );
             nColOffset = nColOffset + nVal;
         }
     }
diff --git a/sc/source/filter/inc/htmlpars.hxx b/sc/source/filter/inc/htmlpars.hxx
index 17e84a5969d6..bac9257f9d5d 100644
--- a/sc/source/filter/inc/htmlpars.hxx
+++ b/sc/source/filter/inc/htmlpars.hxx
@@ -152,13 +152,13 @@ class ScHTMLLayoutParser : public ScHTMLParser
 private:
     Size                aPageSize;
     OUString            aBaseURL;
-    ::std::stack< ScHTMLTableStackEntry* >
+    ::std::stack< std::unique_ptr<ScHTMLTableStackEntry> >
                         aTableStack;
     OUString            aString;
     ScRangeListRef      xLockedList;        // per table
-    OuterMap*           pTables;
+    std::unique_ptr<OuterMap> pTables;
     ScHTMLColOffset     maColOffset;
-    ScHTMLColOffset*    pLocalColOffset;    // per table
+    std::unique_ptr<ScHTMLColOffset> pLocalColOffset;    // per table
     sal_uLong           nFirstTableCell;    // per table
     short               nTableLevel;
     sal_uInt16          nTable;
@@ -169,8 +169,8 @@ private:
     sal_uInt16          nColOffset;         // current, pixel
     sal_uInt16          nColOffsetStart;    // start value per table, in pixel
     sal_uInt16          nOffsetTolerance;   // for use with SeekOffset and related
+    bool                bFirstRow;          // per table, whether in first row
     bool                bTabInTabCell:1;
-    bool                bFirstRow:1;        // per table, whether in first row
     bool                bInCell:1;
     bool                bInTitle:1;
 


More information about the Libreoffice-commits mailing list