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

Caolán McNamara caolanm at redhat.com
Sat Feb 25 15:03:53 UTC 2017


 hwpfilter/qa/cppunit/data/fail/cslist-1.hwp |binary
 hwpfilter/source/hwpfile.cxx                |   83 +++++++---------------------
 hwpfilter/source/hwpfile.h                  |   15 ++---
 3 files changed, 30 insertions(+), 68 deletions(-)

New commits:
commit 283e843be91ef4d727c0815d1b8a0420fd16a7fd
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Feb 24 21:28:10 2017 +0000

    ofz: epic slow use of std::list
    
    Change-Id: I790a3098272101fd33f83f21bdcef1bb061efd76
    Reviewed-on: https://gerrit.libreoffice.org/34635
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/hwpfilter/qa/cppunit/data/fail/cslist-1.hwp b/hwpfilter/qa/cppunit/data/fail/cslist-1.hwp
new file mode 100644
index 0000000..d491f7b
Binary files /dev/null and b/hwpfilter/qa/cppunit/data/fail/cslist-1.hwp differ
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
index 3abfcac..060312a 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -70,7 +70,7 @@ HWPFile::~HWPFile()
     for (; it != plist.end(); ++it)
         delete *it;
 
-    std::list < Table* >::iterator tbl = tables.begin();
+    std::vector< Table* >::iterator tbl = tables.begin();
     for (; tbl != tables.end(); ++tbl)
         delete *tbl;
 
@@ -457,92 +457,53 @@ void HWPFile::AddBox(FBox * box)
     blist.push_back(box);
 }
 
-
 ParaShape *HWPFile::getParaShape(int index)
 {
-    std::list<ParaShape*>::iterator it = pslist.begin();
-
-    for( int i = 0; it != pslist.end(); ++it, i++ ){
-    if( i == index )
-      break;
-    }
-
-    return it != pslist.end() ? *it : nullptr;
+    if (index < 0 || static_cast<unsigned int>(index) >= pslist.size())
+        return nullptr;
+    return pslist[index];
 }
 
-
 CharShape *HWPFile::getCharShape(int index)
 {
-    std::list<CharShape*>::iterator it = cslist.begin();
-
-    for( int i = 0; it != cslist.end(); ++it, i++ ){
-        if( i == index )
-          break;
-    }
-
-    return it != cslist.end() ? *it : nullptr;
+    if (index < 0 || static_cast<unsigned int>(index) >= cslist.size())
+        return nullptr;
+    return cslist[index];
 }
 
-
 FBoxStyle *HWPFile::getFBoxStyle(int index)
 {
-    std::list<FBoxStyle*>::iterator it = fbslist.begin();
-
-    for( int i = 0; it != fbslist.end(); ++it, i++ ){
-        if( i == index )
-          break;
-    }
-
-    return it != fbslist.end() ? *it : nullptr;
+    if (index < 0 || static_cast<unsigned int>(index) >= fbslist.size())
+        return nullptr;
+    return fbslist[index];
 }
 
 DateCode *HWPFile::getDateCode(int index)
 {
-    std::list<DateCode*>::iterator it = datecodes.begin();
-
-    for( int i = 0; it != datecodes.end(); ++it, i++ ){
-        if( i == index )
-          break;
-    }
-
-    return it != datecodes.end() ? *it : nullptr;
+    if (index < 0 || static_cast<unsigned int>(index) >= datecodes.size())
+        return nullptr;
+    return datecodes[index];
 }
 
 HeaderFooter *HWPFile::getHeaderFooter(int index)
 {
-    std::list<HeaderFooter*>::iterator it = headerfooters.begin();
-
-    for( int i = 0; it != headerfooters.end(); ++it, i++ ){
-        if( i == index )
-          break;
-    }
-
-    return it != headerfooters.end() ? *it : nullptr;
+    if (index < 0 || static_cast<unsigned int>(index) >= headerfooters.size())
+        return nullptr;
+    return headerfooters[index];
 }
 
 ShowPageNum *HWPFile::getPageNumber(int index)
 {
-    std::list<ShowPageNum*>::iterator it = pagenumbers.begin();
-
-    for( int i = 0; it != pagenumbers.end(); ++it, i++ ){
-        if( i == index )
-          break;
-    }
-
-    return it != pagenumbers.end() ? *it : nullptr;
-
+    if (index < 0 || static_cast<unsigned int>(index) >= pagenumbers.size())
+        return nullptr;
+    return pagenumbers[index];
 }
 
 Table *HWPFile::getTable(int index)
 {
-    std::list<Table*>::iterator it = tables.begin();
-
-    for( int i = 0; it != tables.end(); ++it, i++ ){
-        if( i == index )
-          break;
-    }
-
-    return it != tables.end() ? *it : nullptr;
+    if (index < 0 || static_cast<unsigned int>(index) >= tables.size())
+        return nullptr;
+    return tables[index];
 }
 
 void HWPFile::AddParaShape(ParaShape * pshape)
diff --git a/hwpfilter/source/hwpfile.h b/hwpfilter/source/hwpfile.h
index 793354e4..1d8da36 100644
--- a/hwpfilter/source/hwpfile.h
+++ b/hwpfilter/source/hwpfile.h
@@ -26,6 +26,7 @@
 #define INCLUDED_HWPFILTER_SOURCE_HWPFILE_H
 
 #include <list>
+#include <vector>
 #include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
@@ -282,13 +283,13 @@ class DLLEXPORT HWPFile
         std::list<EmPicture*> emblist;
         std::list<HyperText*> hyperlist;
         int currenthyper;
-        std::list<ParaShape*> pslist;             /* 스타오피스의 구조상 필요 */
-        std::list<CharShape*> cslist;
-        std::list<FBoxStyle*> fbslist;
-        std::list<DateCode*> datecodes;
-        std::list<HeaderFooter*> headerfooters;
-        std::list<ShowPageNum*> pagenumbers;
-        std::list<Table*> tables;
+        std::vector<ParaShape*> pslist;             /* 스타오피스의 구조상 필요 */
+        std::vector<CharShape*> cslist;
+        std::vector<FBoxStyle*> fbslist;
+        std::vector<DateCode*> datecodes;
+        std::vector<HeaderFooter*> headerfooters;
+        std::vector<ShowPageNum*> pagenumbers;
+        std::vector<Table*> tables;
 
 // for global document handling
         static HWPFile *cur_doc;


More information about the Libreoffice-commits mailing list