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

Julien Nabet serval2412 at yahoo.fr
Wed Oct 18 06:44:28 UTC 2017


 hwpfilter/source/drawing.h     |    2 -
 hwpfilter/source/hbox.cxx      |   36 ++++++------------
 hwpfilter/source/hbox.h        |   19 ++++-----
 hwpfilter/source/hwpfile.cxx   |   82 ++++++++++++++++-------------------------
 hwpfilter/source/hwpfile.h     |   18 ++++-----
 hwpfilter/source/hwpreader.cxx |    6 +--
 6 files changed, 65 insertions(+), 98 deletions(-)

New commits:
commit a05bb7bf718caf2405c5bfaa4a90f6468f2d66ff
Author: Julien Nabet <serval2412 at yahoo.fr>
Date:   Mon Oct 16 22:08:41 2017 +0200

    Replace some lists by vectors in hwpfilter
    
    + simplify some parts
    
    Change-Id: I340d6b6d17f591a58c405965367c15be674103d0
    Reviewed-on: https://gerrit.libreoffice.org/43439
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/hwpfilter/source/drawing.h b/hwpfilter/source/drawing.h
index 0b8191a24a5b..64abf44a67d7 100644
--- a/hwpfilter/source/drawing.h
+++ b/hwpfilter/source/drawing.h
@@ -628,7 +628,7 @@ static HWPPara *LoadParaList()
     HWPFile *hwpf = GetCurrentDoc();
     HIODev *hio = hwpf->SetIODevice(hmem);
 
-    std::list < HWPPara* > plist;
+    std::vector< HWPPara* > plist;
 
     hwpf->ReadParaList(plist);
     hwpf->SetIODevice(hio);
diff --git a/hwpfilter/source/hbox.cxx b/hwpfilter/source/hbox.cxx
index 491353f92e61..ec042a86dbfe 100644
--- a/hwpfilter/source/hbox.cxx
+++ b/hwpfilter/source/hbox.cxx
@@ -349,19 +349,15 @@ TxtBox::~TxtBox()
 {
     for (auto& entry : plists)
     {
-        std::list < HWPPara* >::iterator it = entry.begin();
-        for (; it != entry.end(); ++it)
+        for (auto const& para : entry)
         {
-            HWPPara* pPara = *it;
-            delete pPara;
+            delete para;
         }
     }
 
-    std::list < HWPPara* >::iterator it = caption.begin();
-    for (; it != caption.end(); ++it)
+    for (auto const& para : caption)
     {
-        HWPPara* pPara = *it;
-        delete pPara;
+        delete para;
     }
 }
 
@@ -387,11 +383,9 @@ Picture::~Picture()
     if( pictype == PICTYPE_DRAW && picinfo.picdraw.hdo )
         delete static_cast<HWPDrawingObject *>(picinfo.picdraw.hdo);
 
-    std::list < HWPPara* >::iterator it = caption.begin();
-    for (; it != caption.end(); ++it)
+    for (auto const& para : caption)
     {
-        HWPPara* pPara = *it;
-        delete pPara;
+        delete para;
     }
 }
 
@@ -400,11 +394,9 @@ Picture::~Picture()
 // hidden(15)
 Hidden::~Hidden()
 {
-    std::list < HWPPara* >::iterator it = plist.begin();
-    for (; it != plist.end(); ++it)
+    for (auto const& para : plist)
     {
-        HWPPara* pPara = *it;
-        delete pPara;
+        delete para;
     }
 }
 
@@ -412,11 +404,9 @@ Hidden::~Hidden()
 // header/footer(16)
 HeaderFooter::~HeaderFooter()
 {
-    std::list < HWPPara* >::iterator it = plist.begin();
-    for (; it != plist.end(); ++it)
+    for (auto const& para : plist)
     {
-        HWPPara* pPara = *it;
-        delete pPara;
+        delete para;
     }
 }
 
@@ -424,11 +414,9 @@ HeaderFooter::~HeaderFooter()
 // footnote(17)
 Footnote::~Footnote()
 {
-    std::list < HWPPara* >::iterator it = plist.begin();
-    for (; it != plist.end(); ++it)
+    for (auto const& para : plist)
     {
-        HWPPara* pPara = *it;
-        delete pPara;
+        delete para;
     }
 }
 
diff --git a/hwpfilter/source/hbox.h b/hwpfilter/source/hbox.h
index 6d3d3f62d051..e95698943f8c 100644
--- a/hwpfilter/source/hbox.h
+++ b/hwpfilter/source/hbox.h
@@ -363,12 +363,12 @@ struct TxtBox: public FBox
 /**
  * Paragraph list
  */
-    std::vector<std::list<HWPPara*>> plists;
+    std::vector<std::vector<HWPPara*>> plists;
 
 /**
  * Caption
  */
-    std::list<HWPPara*> caption;
+    std::vector<HWPPara*> caption;
 
     TxtBox();
     virtual ~TxtBox() override;
@@ -511,14 +511,13 @@ struct Table
 {
      Table() : box(nullptr) {};
      ~Table() {
-          std::list<TCell*>::iterator it = cells.begin();
-          for( ; it != cells.end(); ++it)
-                delete *it;
+          for (auto const& cell : cells)
+                delete cell;
      };
 
      Columns columns;
      Rows    rows;
-     std::list<TCell*> cells;
+     std::vector<TCell*> cells;
      TxtBox *box;
 };
 
@@ -626,7 +625,7 @@ struct Picture: public FBox
     PicDef    picinfo;
     char      reserved3[9];
 
-    std::list<HWPPara*> caption;
+    std::vector<HWPPara*> caption;
 /**
  * It's for the Drawing object
  */
@@ -669,7 +668,7 @@ struct Hidden: public HBox
     hchar     dummy;
 
     unsigned char info[8];                        // h, next, dummy
-    std::list<HWPPara*> plist;
+    std::vector<HWPPara*> plist;
 
     Hidden();
     virtual ~Hidden() override;
@@ -698,7 +697,7 @@ struct HeaderFooter: public HBox
 /**
  * Paragraph list of header or footer
  */
-    std::list<HWPPara*> plist;
+    std::vector<HWPPara*> plist;
 
     HeaderFooter();
     virtual ~HeaderFooter() override;
@@ -731,7 +730,7 @@ struct Footnote: public HBox
 /**
  * Paragraph list of Footnote objects
  */
-    std::list<HWPPara*> plist;
+    std::vector<HWPPara*> plist;
 
     Footnote();
     virtual ~Footnote() override;
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
index a693f15d3d55..2bb3350fc4a5 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -63,25 +63,20 @@ HWPFile::~HWPFile()
     delete oledata;
     delete hiodev;
 
-    std::list < ColumnInfo* >::iterator it_column = columnlist.begin();
-    for (; it_column != columnlist.end(); ++it_column)
-        delete *it_column;
+    for (auto const& column : columnlist)
+        delete column;
 
-    std::list < HWPPara* >::iterator it = plist.begin();
-    for (; it != plist.end(); ++it)
-        delete *it;
+    for (auto const& paragraph : plist)
+        delete paragraph;
 
-    std::vector< Table* >::iterator tbl = tables.begin();
-    for (; tbl != tables.end(); ++tbl)
-        delete *tbl;
+    for (auto const& table : tables)
+        delete table;
 
-    std::list<EmPicture*>::iterator emb = emblist.begin();
-    for (; emb != emblist.end(); ++emb)
-        delete *emb;
+    for (auto const& emb : emblist)
+        delete emb;
 
-    std::list<HyperText*>::iterator hyp = hyperlist.begin();
-    for (; hyp != hyperlist.end(); ++hyp)
-        delete *hyp;
+    for (auto const& hyperlink : hyperlist)
+        delete hyperlink;
 }
 
 int HWPFile::ReadHwpFile(HStream * stream)
@@ -237,7 +232,7 @@ void HWPFile::ParaListRead()
     ReadParaList(plist);
 }
 
-bool HWPFile::ReadParaList(std::list < HWPPara* > &aplist, unsigned char flag)
+bool HWPFile::ReadParaList(std::vector < HWPPara* > &aplist, unsigned char flag)
 {
     std::unique_ptr<HWPPara> spNode( new HWPPara );
     unsigned char tmp_etcflag;
@@ -401,43 +396,32 @@ void HWPFile::TagsRead()
 
 ColumnDef *HWPFile::GetColumnDef(int num)
 {
-    std::list<ColumnInfo*>::iterator it = columnlist.begin();
-
-    for(int i = 0; it != columnlist.end() ; ++it, i++){
-        if( i == num )
-            break;
-    }
-
-    if( it != columnlist.end() )
-        return (*it)->coldef;
+    if (static_cast<size_t>(num) < columnlist.size())
+        return columnlist[num]->coldef;
     else
         return nullptr;
 }
+
 /* Index of @return starts from 1 */
 int HWPFile::GetPageMasterNum(int page)
 {
-    std::list<ColumnInfo*>::iterator it = columnlist.begin();
-    int i;
-
-    for( i = 1 ; it != columnlist.end() ; ++it, i++){
-        ColumnInfo *now = *it;
-        if( page < now->start_page )
-            return i-1;
+    int i = 0;
+    for (auto const& column : columnlist)
+    {
+        if( page < column->start_page )
+            return i;
+        ++i;
     }
-    return i-1;
+    return i;
 }
 
 HyperText *HWPFile::GetHyperText()
 {
-    std::list<HyperText*>::iterator it = hyperlist.begin();
-
-    for( int i = 0; it != hyperlist.end(); ++it, i++ ){
-        if( i == currenthyper )
-          break;
-    }
-
-    currenthyper++;
-    return it != hyperlist.end() ? *it : nullptr;
+    ++currenthyper;
+    if (static_cast<size_t>(currenthyper) <= hyperlist.size())
+        return hyperlist[currenthyper-1];
+    else
+        return nullptr;
 }
 
 EmPicture *HWPFile::GetEmPicture(Picture * pic)
@@ -448,10 +432,9 @@ EmPicture *HWPFile::GetEmPicture(Picture * pic)
     name[1] = 'W';
     name[2] = 'P';
 
-    std::list < EmPicture* >::iterator it = emblist.begin();
-    for (; it != emblist.end(); ++it)
-        if (strcmp(name, (*it)->name) == 0)
-            return *it;
+    for (auto const& emb : emblist)
+        if (strcmp(name, emb->name) == 0)
+            return emb;
     return nullptr;
 }
 
@@ -461,10 +444,9 @@ EmPicture *HWPFile::GetEmPictureByName(char * name)
     name[1] = 'W';
     name[2] = 'P';
 
-    std::list < EmPicture* >::iterator it = emblist.begin();
-    for (; it != emblist.end(); ++it)
-        if (strcmp(name, (*it)->name) == 0)
-            return *it;
+    for (auto const& emb : emblist)
+        if (strcmp(name, emb->name) == 0)
+            return emb;
     return nullptr;
 }
 
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
index 55a94b628ac5..fee55b75a91c 100644
--- a/hwpfilter/source/hwpfile.h
+++ b/hwpfilter/source/hwpfile.h
@@ -160,7 +160,7 @@ class DLLEXPORT HWPFile
 /**
  * Reads main paragraph list
  */
-        bool ReadParaList(std::list<HWPPara*> &aplist, unsigned char flag = 0);
+        bool ReadParaList(std::vector<HWPPara*> &aplist, unsigned char flag = 0);
 /**
  * Sets if the stream is compressed
  */
@@ -282,14 +282,14 @@ class DLLEXPORT HWPFile
         HWPInfo   _hwpInfo;
         HWPFont   _hwpFont;
         HWPStyle  _hwpStyle;
-        std::list<ColumnInfo*> columnlist;
-          // paragraph linked list
-        std::list<HWPPara*> plist;
-          // floating box linked list
-        std::list<FBox*> blist;
-          // embedded picture list(tag datas)
-        std::list<EmPicture*> emblist;
-        std::list<HyperText*> hyperlist;
+        std::vector<ColumnInfo*> columnlist;
+        // paragraph list
+        std::vector<HWPPara*> plist;
+        // floating box list
+        std::vector<FBox*> blist;
+        // embedded picture list(tag datas)
+        std::vector<EmPicture*> emblist;
+        std::vector<HyperText*> hyperlist;
         int currenthyper;
         std::vector<std::shared_ptr<ParaShape>> pslist;
         std::vector<std::shared_ptr<CharShape>> cslist;
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 47869520de23..06cef295d392 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -1921,9 +1921,8 @@ void HwpReader::makeTableStyle(Table *tbl)
     }
 
 // cell
-    for (std::list<TCell*>::iterator it = tbl->cells.begin(), aEnd = tbl->cells.end(); it != aEnd; ++it)
+    for (auto const& tcell : tbl->cells)
     {
-        TCell *tcell = *it;
         sprintf(buf,"Table%d.%c%d",hbox->style.boxnum, 'A'+ tcell->nColumnIndex, tcell->nRowIndex +1);
         padd("style:name", sXML_CDATA, ascii( buf ));
         padd("style:family", sXML_CDATA,"table-cell");
@@ -3475,9 +3474,8 @@ void HwpReader::makeTable(TxtBox * hbox)
 
 // cell
     int j = -1, k = -1;
-    for (std::list<TCell*>::iterator it = tbl->cells.begin(), aEnd = tbl->cells.end(); it != aEnd; ++it)
+    for (auto const& tcell : tbl->cells)
     {
-        TCell *tcell = *it;
         if( tcell->nRowIndex > j )
         {
             if( j > k )


More information about the Libreoffice-commits mailing list