[poppler] 7 commits - CMakeLists.txt cpp/poppler-font.cpp glib/poppler-document.cc goo/GooList.cc goo/GooList.h poppler/Annot.cc poppler/FontInfo.cc poppler/Form.cc poppler/GfxState.cc poppler/GlobalParams.cc poppler/JBIG2Stream.cc poppler/Link.cc poppler/OptionalContent.cc poppler/Outline.cc poppler/PDFDocFactory.cc poppler/PSOutputDev.cc poppler/TextOutputDev.cc qt5/src splash/SplashBitmap.cc splash/Splash.cc utils/HtmlOutputDev.cc utils/pdfdetach.cc utils/printencodings.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 5 09:52:04 UTC 2018


 CMakeLists.txt              |    1 
 cpp/poppler-font.cpp        |    2 
 glib/poppler-document.cc    |    4 -
 goo/GooList.cc              |  136 --------------------------------------------
 goo/GooList.h               |  105 ++++++++-------------------------
 poppler/Annot.cc            |   16 ++---
 poppler/FontInfo.cc         |    2 
 poppler/Form.cc             |    8 +-
 poppler/GfxState.cc         |   12 +--
 poppler/GlobalParams.cc     |   12 +--
 poppler/JBIG2Stream.cc      |   37 +++++------
 poppler/Link.cc             |   16 ++---
 poppler/OptionalContent.cc  |    7 +-
 poppler/Outline.cc          |    6 -
 poppler/PDFDocFactory.cc    |   10 +--
 poppler/PSOutputDev.cc      |    4 -
 poppler/TextOutputDev.cc    |   32 +++++-----
 qt5/src/poppler-fontinfo.cc |    2 
 splash/Splash.cc            |    2 
 splash/SplashBitmap.cc      |    4 -
 utils/HtmlOutputDev.cc      |   30 ++++-----
 utils/pdfdetach.cc          |    6 -
 utils/printencodings.cc     |   15 +---
 23 files changed, 136 insertions(+), 333 deletions(-)

New commits:
commit 101728e8a5089c01fc7bca950db0e8ae84d27b47
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Sun Aug 26 22:10:47 2018 +0200

    Remove GooList::append since the single element variant is std::vector::push_back and the list variant is used only once.

diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index dd1d0b9d..83f6aea6 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -2211,7 +2211,7 @@ poppler_fonts_iter_copy (PopplerFontsIter *iter)
 	new_iter->items = new GooList ();
 	for (int i = 0; i < iter->items->getLength(); i++) {
 		FontInfo *info = (FontInfo *)iter->items->get(i);
-		new_iter->items->append (new FontInfo (*info));
+		new_iter->items->push_back (new FontInfo (*info));
 	}
 
 	return new_iter;
diff --git a/goo/GooList.h b/goo/GooList.h
index 9773ae89..52c8ade4 100644
--- a/goo/GooList.h
+++ b/goo/GooList.h
@@ -48,27 +48,12 @@ struct GooList : public std::vector<void *> {
   explicit GooList(const std::vector<void *>& vec) : std::vector<void *>(vec) {}
   explicit GooList(std::vector<void *>&& vec) : std::vector<void *>(std::move(vec)) {}
 
-  //----- general
-
   // Get the number of elements.
   int getLength() const { return size(); }
 
-  //----- ordered list support
-
   // Return the <i>th element.
   // Assumes 0 <= i < length.
   void *get(int i) const { return (*this)[i]; }
-
-  // Append an element to the end of the list.
-  void append(void *p) {
-    push_back(p);
-  }
-
-  // Append another list to the end of this one.
-  void append(GooList *list) {
-    reserve(size() + list->size());
-    static_cast<std::vector<void *>&>(*this).insert(end(), list->begin(), list->end());
-  }
 };
 
 template<typename T>
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index eeb6b521..b92d929c 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -4130,7 +4130,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
         for (j = i + 1;
             j < da->getLength() && !Lexer::isSpace(da->getChar(j));
             ++j) ;
-        daToks->append(new GooString(da, i, j - i));
+	daToks->push_back(new GooString(da, i, j - i));
         i = j;
       }
     }
@@ -4540,7 +4540,7 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
 	for (j = i + 1;
 	     j < da->getLength() && !Lexer::isSpace(da->getChar(j));
 	     ++j) ;
-	daToks->append(new GooString(da, i, j - i));
+	daToks->push_back(new GooString(da, i, j - i));
 	i = j;
       }
     }
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index 18f21f40..c54d21b0 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -115,7 +115,7 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, GooList *fontsList)
 
         // add this font to the list if not already found
         if (fonts.find(fontRef.num) == fonts.end()) {
-          fontsList->append(new FontInfo(font, xrefA));
+	  fontsList->push_back(new FontInfo(font, xrefA));
           fonts.insert(fontRef.num);
         }
       }
diff --git a/poppler/Form.cc b/poppler/Form.cc
index a0e324ea..30ded164 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -1274,7 +1274,7 @@ int FormFieldText::tokenizeDA(const GooString* da, GooList* daToks, const char*
         GooString* tok = new GooString(da, i, j - i);
         if (searchTok && !tok->cmp(searchTok))
           idx = daToks->getLength();
-        daToks->append(tok);
+	daToks->push_back(tok);
         i = j;
       }
     }
diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index 81c1244f..c31cc1ff 100644
--- a/poppler/GfxState.cc
+++ b/poppler/GfxState.cc
@@ -2893,7 +2893,7 @@ void GfxSeparationColorSpace::createMapping(GooList *separationList, int maxSepC
         return;
       }
       *mapping = separationList->getLength() + 4;
-      separationList->append(copy());
+      separationList->push_back(copy());
       overprintMask = newOverprintMask;
       break;
   }
@@ -2981,7 +2981,7 @@ GfxColorSpace *GfxDeviceNColorSpace::copy() {
   for (i = 0; i < sepsCS->getLength(); i++) {
     GfxSeparationColorSpace *scs = (GfxSeparationColorSpace *) sepsCS->get(i);
     if (likely(scs != nullptr)) {
-      sepsCSA->append(scs->copy());
+      sepsCSA->push_back(scs->copy());
     }
   }
   if (mapping != nullptr) {
@@ -3049,7 +3049,7 @@ GfxColorSpace *GfxDeviceNColorSpace::parse(GfxResources *res, Array *arr, Output
       for (i = 0; i < colorants->getLength(); i++) {
         Object obj3 = colorants->getVal(i);
         if (obj3.isArray()) {
-          separationList->append(GfxSeparationColorSpace::parse(res, obj3.getArray(), out, state, recursion));
+	  separationList->push_back(GfxSeparationColorSpace::parse(res, obj3.getArray(), out, state, recursion));
         } else {
           error(errSyntaxWarning, -1, "Bad DeviceN color space (colorant value entry is not an Array)");
           goto err5;
@@ -3208,13 +3208,13 @@ void GfxDeviceNColorSpace::createMapping(GooList *separationList, int maxSepComp
         mapping[i] = separationList->getLength() + 4;
         newOverprintMask |= startOverprintMask;
         if (nComps == 1)
-          separationList->append(new GfxSeparationColorSpace(names[i]->copy(),alt->copy(), func->copy()));
+	  separationList->push_back(new GfxSeparationColorSpace(names[i]->copy(),alt->copy(), func->copy()));
         else {
           for (int k = 0; k < sepsCS->getLength(); k++) {
             GfxSeparationColorSpace *sepCS = (GfxSeparationColorSpace *)sepsCS->get(k);
             if (!sepCS->getName()->cmp(names[i])) {
               found = gTrue;
-              separationList->append(sepCS->copy());
+	      separationList->push_back(sepCS->copy());
               break;
             }
           }
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 9a61c733..0d47025f 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -240,7 +240,7 @@ public:
   void scanWindowsFonts(GooString *winFontDir);
 #endif
 #ifdef WITH_FONTCONFIGURATION_FONTCONFIG
-  void addFcFont(SysFontInfo *si) {fonts->append(si);}
+  void addFcFont(SysFontInfo *si) {fonts->push_back(si);}
 #endif
 private:
 
@@ -491,7 +491,7 @@ void GlobalParams::scanEncodingDirs() {
   dir = new GDir(dataPathBuffer, gFalse);
   while (entry = dir->getNextEntry(), entry != nullptr) {
     addCMapDir(entry->getName(), entry->getFullPath());
-    toUnicodeDirs->append(entry->getFullPath()->copy());
+    toUnicodeDirs->push_back(entry->getFullPath()->copy());
     delete entry;
   }
   delete dir;
@@ -1217,10 +1217,10 @@ GooList *GlobalParams::getEncodingNames()
 {
   auto* const result = new GooList;
   for (const auto& unicodeMap : residentUnicodeMaps) {
-    result->append(new GooString(unicodeMap.first));
+    result->push_back(new GooString(unicodeMap.first));
   }
   for (const auto& unicodeMap : unicodeMaps) {
-    result->append(new GooString(unicodeMap.first));
+    result->push_back(new GooString(unicodeMap.first));
   }
   return result;
 }
diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc
index 89c8123a..17b90d7a 100644
--- a/poppler/JBIG2Stream.cc
+++ b/poppler/JBIG2Stream.cc
@@ -1639,7 +1639,7 @@ GBool JBIG2Stream::readSymbolDictSeg(Guint segNum, Guint length,
 	}
 	numInputSyms += j;
       } else if (seg->getType() == jbig2SegCodeTable) {
-        codeTables->append(seg);
+	codeTables->push_back(seg);
       }
     } else {
       delete codeTables;
@@ -1980,7 +1980,7 @@ GBool JBIG2Stream::readSymbolDictSeg(Guint segNum, Guint length,
   }
 
   // store the new symbol dict
-  segments->append(symbolDict);
+  segments->push_back(symbolDict);
 
   return gTrue;
 
@@ -2086,7 +2086,7 @@ void JBIG2Stream::readTextRegionSeg(Guint segNum, GBool imm,
       if (seg->getType() == jbig2SegSymbolDict) {
 	numSyms += ((JBIG2SymbolDict *)seg)->getSize();
       } else if (seg->getType() == jbig2SegCodeTable) {
-	codeTables->append(seg);
+	codeTables->push_back(seg);
       }
     } else {
       error(errSyntaxError, curStr->getPos(), "Invalid segment reference in JBIG2 text region");
@@ -2293,7 +2293,7 @@ void JBIG2Stream::readTextRegionSeg(Guint segNum, GBool imm,
     // store the region bitmap
     } else {
       bitmap->setSegNum(segNum);
-      segments->append(bitmap);
+      segments->push_back(bitmap);
     }
   }
 
@@ -2632,7 +2632,7 @@ void JBIG2Stream::readPatternDictSeg(Guint segNum, Guint length) {
   delete bitmap;
 
   // store the new pattern dict
-  segments->append(patternDict);
+  segments->push_back(patternDict);
 
   return;
 
@@ -2809,7 +2809,7 @@ void JBIG2Stream::readHalftoneRegionSeg(Guint segNum, GBool imm,
 
   // store the region bitmap
   } else {
-    segments->append(bitmap);
+    segments->push_back(bitmap);
   }
 
   return;
@@ -2885,7 +2885,7 @@ void JBIG2Stream::readGenericRegionSeg(Guint segNum, GBool imm,
   // store the region bitmap
   } else {
     bitmap->setSegNum(segNum);
-    segments->append(bitmap);
+    segments->push_back(bitmap);
   }
 
   // immediate generic segments can have an unspecified length, in
@@ -3798,7 +3798,7 @@ void JBIG2Stream::readGenericRefinementRegionSeg(Guint segNum, GBool imm,
   } else {
     if (bitmap) {
       bitmap->setSegNum(segNum);
-      segments->append(bitmap);
+      segments->push_back(bitmap);
     } else {
       error(errSyntaxError, curStr->getPos(), "readGenericRefinementRegionSeg with null bitmap");
     }
@@ -4136,7 +4136,7 @@ void JBIG2Stream::readCodeTableSeg(Guint segNum, Guint length) {
   huffDecoder->buildTable(huffTab, i);
 
   // create and store the new table segment
-  segments->append(new JBIG2CodeTable(segNum, huffTab));
+  segments->push_back(new JBIG2CodeTable(segNum, huffTab));
 
   return;
 
diff --git a/poppler/Link.cc b/poppler/Link.cc
index 0758428b..877e5213 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -176,7 +176,7 @@ LinkAction *LinkAction::parseAction(const Object *obj, const GooString *baseURI,
     }
 
     actionList = new GooList(1);
-    actionList->append(parseAction(&nextObj, nullptr, seenNextActions));
+    actionList->push_back(parseAction(&nextObj, nullptr, seenNextActions));
   } else if (nextObj.isArray()) {
     const Array *a = nextObj.getArray();
     const int n = a->getLength();
@@ -198,7 +198,7 @@ LinkAction *LinkAction::parseAction(const Object *obj, const GooString *baseURI,
           }
       }
 
-      actionList->append(parseAction(&obj3, nullptr, seenNextActions));
+      actionList->push_back(parseAction(&obj3, nullptr, seenNextActions));
     }
   }
 
@@ -833,7 +833,7 @@ LinkOCGState::LinkOCGState(const Object *obj) {
       Object obj2 = obj1.arrayGetNF(i);
       if (obj2.isName()) {
         if (stList)
-	  stateList->append(stList);
+	  stateList->push_back(stList);
 
 	const char *name = obj2.getName();
 	stList = new StateList();
@@ -855,7 +855,7 @@ LinkOCGState::LinkOCGState(const Object *obj) {
 	  Ref *item = new Ref();
 	  item->num = ocgRef.num;
 	  item->gen = ocgRef.gen;
-	  stList->list->append(item);
+	  stList->list->push_back(item);
 	} else {
 	  error(errSyntaxWarning, -1, "Invalid OCG Action State array, expected name instead of ref");
 	}
@@ -865,7 +865,7 @@ LinkOCGState::LinkOCGState(const Object *obj) {
     }
     // Add the last group
     if (stList)
-      stateList->append(stList);
+      stateList->push_back(stList);
   } else {
     error(errSyntaxWarning, -1, "Invalid OCGState action");
     delete stateList;
diff --git a/poppler/OptionalContent.cc b/poppler/OptionalContent.cc
index b197ac28..edb55b5f 100644
--- a/poppler/OptionalContent.cc
+++ b/poppler/OptionalContent.cc
@@ -438,14 +438,15 @@ void OCDisplayNode::addChild(OCDisplayNode *child) {
   if (!children) {
     children = new GooList();
   }
-  children->append(child);
+  children->push_back(child);
 }
 
 void OCDisplayNode::addChildren(GooList *childrenA) {
   if (!children) {
     children = new GooList();
   }
-  children->append(childrenA);
+  children->reserve(children->size() + childrenA->size());
+  children->insert(children->end(), childrenA->begin(), childrenA->end());
   delete childrenA;
 }
 
diff --git a/poppler/Outline.cc b/poppler/Outline.cc
index 6cb5d258..20db8967 100644
--- a/poppler/Outline.cc
+++ b/poppler/Outline.cc
@@ -134,7 +134,7 @@ GooList *OutlineItem::readItemList(OutlineItem *parent, const Object *firstItemR
     }
     alreadyRead[p->getRefNum()] = 1;
     OutlineItem *item = new OutlineItem(obj.getDict(), p->getRefNum(), parent, xrefA);
-    items->append(item);
+    items->push_back(item);
     p = &item->nextRef;
   }
 
diff --git a/poppler/PDFDocFactory.cc b/poppler/PDFDocFactory.cc
index 9e9c510b..ff160366 100644
--- a/poppler/PDFDocFactory.cc
+++ b/poppler/PDFDocFactory.cc
@@ -67,7 +67,7 @@ PDFDocFactory::createPDFDoc(const GooString &uri, GooString *ownerPassword,
 
 void PDFDocFactory::registerPDFDocBuilder(PDFDocBuilder *pdfDocBuilder)
 {
-  builders->append(pdfDocBuilder);
+  builders->push_back(pdfDocBuilder);
 }
 
 
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index d54c45f1..25f50b72 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -1384,7 +1384,7 @@ void PSOutputDev::postInit()
       }
       if (!name)
         name = GooString::format("{0:d}x{1:d}mm", int(w*25.4/72), int(h*25.4/72));
-      paperSizes->append(new PSOutPaperSize(name, w, h));
+      paperSizes->push_back(new PSOutPaperSize(name, w, h));
     }
     pagePaperSize.insert(std::pair<int,int>(pg, i));
     if (!paperMatch)
diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc
index 9402adbe..6c2eb7f5 100644
--- a/poppler/TextOutputDev.cc
+++ b/poppler/TextOutputDev.cc
@@ -2272,7 +2272,7 @@ TextWordList::TextWordList(TextPage *text, GBool physLayout) {
 
   if (text->rawOrder) {
     for (word = text->rawWords; word; word = word->next) {
-      words->append(word);
+      words->push_back(word);
     }
 
   } else if (physLayout) {
@@ -2301,7 +2301,7 @@ TextWordList::TextWordList(TextPage *text, GBool physLayout) {
     }
     qsort(wordArray, nWords, sizeof(TextWord *), &TextWord::cmpYX);
     for (i = 0; i < nWords; ++i) {
-      words->append(wordArray[i]);
+      words->push_back(wordArray[i]);
     }
     gfree(wordArray);
 
@@ -2310,7 +2310,7 @@ TextWordList::TextWordList(TextPage *text, GBool physLayout) {
       for (blk = flow->blocks; blk; blk = blk->next) {
 	for (line = blk->lines; line; line = line->next) {
 	  for (word = line->words; word; word = word->next) {
-	    words->append(word);
+	    words->push_back(word);
 	  }
 	}
       }
@@ -2476,7 +2476,7 @@ void TextPage::updateFont(GfxState *state) {
   }
   if (!curFont) {
     curFont = new TextFontInfo(state);
-    fonts->append(curFont);
+    fonts->push_back(curFont);
   }
 
   // adjust the font size
@@ -2753,11 +2753,11 @@ void TextPage::addWord(TextWord *word) {
 }
 
 void TextPage::addUnderline(double x0, double y0, double x1, double y1) {
-  underlines->append(new TextUnderline(x0, y0, x1, y1));
+  underlines->push_back(new TextUnderline(x0, y0, x1, y1));
 }
 
 void TextPage::addLink(int xMin, int yMin, int xMax, int yMax, AnnotLink *link) {
-  links->append(new TextLink(xMin, yMin, xMax, yMax, link));
+  links->push_back(new TextLink(xMin, yMin, xMax, yMax, link));
 }
 
 void TextPage::coalesce(GBool physLayout, double fixedPitch, GBool doHTML) {
@@ -4445,7 +4445,7 @@ void TextSelectionDumper::visitLine (TextLine *line,
 void TextSelectionDumper::visitWord (TextWord *word, int begin, int end,
                                      PDFRectangle *selection)
 {
-  words->append(new TextWordSelection(word, begin, end));
+  words->push_back(new TextWordSelection(word, begin, end));
 }
 
 void TextSelectionDumper::endPage()
@@ -4553,7 +4553,7 @@ void TextSelectionSizer::visitLine (TextLine *line,
 			   floor (y1 * scale),
 			   ceil (x2 * scale),
 			   ceil (y2 * scale));
-  list->append (rect);
+  list->push_back (rect);
 }
 
 
@@ -4657,7 +4657,7 @@ void TextSelectionPainter::visitLine (TextLine *line,
 void TextSelectionPainter::visitWord (TextWord *word, int begin, int end,
 				      PDFRectangle *selection)
 {
-  selectionList->append(new TextWordSelection(word, begin, end));
+  selectionList->push_back(new TextWordSelection(word, begin, end));
 }
 
 void TextSelectionPainter::endPage()
diff --git a/splash/Splash.cc b/splash/Splash.cc
index 184659f5..e8b76ec0 100644
--- a/splash/Splash.cc
+++ b/splash/Splash.cc
@@ -5283,7 +5283,7 @@ SplashError Splash::composite(SplashBitmap *src, int xSrc, int ySrc,
 
   if(src->getSeparationList()->getLength() > bitmap->getSeparationList()->getLength()) {
     for (x = bitmap->getSeparationList()->getLength(); x < src->getSeparationList()->getLength(); x++)
-      bitmap->getSeparationList()->append(((GfxSeparationColorSpace *)src->getSeparationList()->get(x))->copy());
+      bitmap->getSeparationList()->push_back(((GfxSeparationColorSpace *)src->getSeparationList()->get(x))->copy());
   }
   if (src->alpha) {
     pipeInit(&pipe, xDest, yDest, nullptr, pixel,
diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc
index 84add457..8ae41ad0 100644
--- a/splash/SplashBitmap.cc
+++ b/splash/SplashBitmap.cc
@@ -129,7 +129,7 @@ SplashBitmap::SplashBitmap(int widthA, int heightA, int rowPadA,
   separationList = new GooList();
   if (separationListA != nullptr)
     for (int i = 0; i < separationListA->getLength(); i++)
-      separationList->append(((GfxSeparationColorSpace *) separationListA->get(i))->copy());
+      separationList->push_back(((GfxSeparationColorSpace *) separationListA->get(i))->copy());
 }
 
 SplashBitmap *SplashBitmap::copy(SplashBitmap *src) {
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 4cd7b9fd..df3171db 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -1019,7 +1019,7 @@ void HtmlPage::setDocName(const char *fname){
 
 void HtmlPage::addImage(GooString *fname, GfxState *state) {
   HtmlImage *img = new HtmlImage(fname, state);
-  imgList->append(img);
+  imgList->push_back(img);
 }
 
 //------------------------------------------------------------------------
@@ -1129,11 +1129,11 @@ HtmlOutputDev::HtmlOutputDev(Catalog *catalogA, const char *fileName, const char
   pages = new HtmlPage(rawOrder, extension);
   
   glMetaVars = new GooList();
-  glMetaVars->append(new HtmlMetaVar("generator", "pdftohtml 0.36"));  
-  if( author ) glMetaVars->append(new HtmlMetaVar("author", author));  
-  if( keywords ) glMetaVars->append(new HtmlMetaVar("keywords", keywords));  
-  if( date ) glMetaVars->append(new HtmlMetaVar("date", date));  
-  if( subject ) glMetaVars->append(new HtmlMetaVar("subject", subject));
+  glMetaVars->push_back(new HtmlMetaVar("generator", "pdftohtml 0.36"));
+  if( author ) glMetaVars->push_back(new HtmlMetaVar("author", author));
+  if( keywords ) glMetaVars->push_back(new HtmlMetaVar("keywords", keywords));
+  if( date ) glMetaVars->push_back(new HtmlMetaVar("date", date));
+  if( subject ) glMetaVars->push_back(new HtmlMetaVar("subject", subject));
  
   maxPageWidth = 0;
   maxPageHeight = 0;
diff --git a/utils/pdfdetach.cc b/utils/pdfdetach.cc
index 860b55c2..f65b435f 100644
--- a/utils/pdfdetach.cc
+++ b/utils/pdfdetach.cc
@@ -163,7 +163,7 @@ int main(int argc, char *argv[]) {
 
   embeddedFiles = new GooList();
   for (i = 0; i < doc->getCatalog()->numEmbeddedFiles(); ++i)
-    embeddedFiles->append(doc->getCatalog()->embeddedFile(i));
+    embeddedFiles->push_back(doc->getCatalog()->embeddedFile(i));
 
   nPages = doc->getCatalog()->getNumPages();
   for (i = 0; i < nPages; ++i) {
@@ -178,7 +178,7 @@ int main(int argc, char *argv[]) {
       annot = annots->getAnnot(j);
       if (annot->getType() != Annot::typeFileAttachment)
         continue;
-      embeddedFiles->append(new FileSpec(static_cast<AnnotFileAttachment *>(annot)->getFile()));
+      embeddedFiles->push_back(new FileSpec(static_cast<AnnotFileAttachment *>(annot)->getFile()));
     }
   }
 
commit e44e90b434434de5ea3b23d3a40ded7a5ad05b1c
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Sun Aug 26 21:46:31 2018 +0200

    Remove GooList::put as it is apparently unused.

diff --git a/goo/GooList.h b/goo/GooList.h
index 0fbb45ef..9773ae89 100644
--- a/goo/GooList.h
+++ b/goo/GooList.h
@@ -59,10 +59,6 @@ struct GooList : public std::vector<void *> {
   // Assumes 0 <= i < length.
   void *get(int i) const { return (*this)[i]; }
 
-  // Replace the <i>th element.
-  // Assumes 0 <= i < length.
-  void put(int i, void *p) { (*this)[i] = p; }
-
   // Append an element to the end of the list.
   void append(void *p) {
     push_back(p);
commit 571a321721c5b166c402995b0a8e015f10948c31
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Sun Aug 26 21:42:47 2018 +0200

    Turn deleteGooList macro into a template to improve type checking and diagnostics.

diff --git a/cpp/poppler-font.cpp b/cpp/poppler-font.cpp
index fcf0f7a7..041a10ce 100644
--- a/cpp/poppler-font.cpp
+++ b/cpp/poppler-font.cpp
@@ -221,7 +221,7 @@ std::vector<font_info> font_iterator::next()
     for (int i = 0; i < items->getLength(); ++i) {
         fonts[i] = font_info(*new font_info_private((FontInfo *)items->get(i)));
     }
-    deleteGooList(items, FontInfo);
+    deleteGooList<FontInfo>(items);
     return fonts;
 }
 
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index fc69d8c3..dd1d0b9d 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -2229,7 +2229,7 @@ poppler_fonts_iter_free (PopplerFontsIter *iter)
 	if (G_UNLIKELY (iter == nullptr))
 		return;
 
-	deleteGooList (iter->items, FontInfo);
+	deleteGooList<FontInfo> (iter->items);
 
 	g_slice_free (PopplerFontsIter, iter);
 }
diff --git a/goo/GooList.h b/goo/GooList.h
index d2d14df6..0fbb45ef 100644
--- a/goo/GooList.h
+++ b/goo/GooList.h
@@ -44,6 +44,7 @@ struct GooList : public std::vector<void *> {
   GooList(const GooList &other) = delete;
   GooList& operator=(const GooList &other) = delete;
 
+  // Zero cost conversion from std::vector
   explicit GooList(const std::vector<void *>& vec) : std::vector<void *>(vec) {}
   explicit GooList(std::vector<void *>&& vec) : std::vector<void *>(std::move(vec)) {}
 
@@ -74,14 +75,10 @@ struct GooList : public std::vector<void *> {
   }
 };
 
-#define deleteGooList(list, T)                        \
-  do {                                              \
-    GooList *_list = (list);                          \
-    {                                               \
-      int _i;                                       \
-      for (_i = 0; _i < _list->getLength(); ++_i) { \
-        delete (T*)_list->get(_i);                  \
-      }                                             \
-      delete _list;                                 \
-    }                                               \
-  } while (0)
+template<typename T>
+inline void deleteGooList(GooList* list) {
+  for (auto ptr : *list) {
+    delete static_cast<T *>(ptr);
+  }
+  delete list;
+}
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 0ec9e22c..eeb6b521 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -829,7 +829,7 @@ DefaultAppearance::DefaultAppearance(GooString *da) {
         }
       }
     }
-    deleteGooList(daToks, GooString);
+    deleteGooList<GooString>(daToks);
   }
 }
 
@@ -4191,7 +4191,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
   }
   if (!font) {
     if (daToks) {
-      deleteGooList(daToks, GooString);
+      deleteGooList<GooString>(daToks);
     }
     return false;
   }
@@ -4501,7 +4501,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
     appearBuf->append("EMC\n");
   }
   if (daToks) {
-    deleteGooList(daToks, GooString);
+    deleteGooList<GooString>(daToks);
   }
   if (freeText) {
     delete text;
@@ -4574,7 +4574,7 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
   }
   if (!font) {
     if (daToks) {
-      deleteGooList(daToks, GooString);
+      deleteGooList<GooString>(daToks);
     }
     return false;
   }
@@ -4592,7 +4592,7 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
       if (fieldChoice->getChoice(i) == nullptr) {
         error(errSyntaxError, -1, "Invalid annotation listbox");
         if (daToks) {
-          deleteGooList(daToks, GooString);
+	  deleteGooList<GooString>(daToks);
         }
         delete convertedText;
         return false;
@@ -4690,7 +4690,7 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
   }
 
   if (daToks) {
-    deleteGooList(daToks, GooString);
+    deleteGooList<GooString>(daToks);
   }
 
   delete convertedText;
diff --git a/poppler/Form.cc b/poppler/Form.cc
index 68d3b602..a0e324ea 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -1225,7 +1225,7 @@ double FormFieldText::getTextFontSize()
     if (!p || *p)
       fontSize = -1;
   }
-  deleteGooList(daToks, GooString);
+  deleteGooList<GooString>(daToks);
   return fontSize;
 }
 
@@ -1236,7 +1236,7 @@ void FormFieldText::setTextFontSize(int fontSize)
     int idx = parseDA(daToks);
     if (idx == -1) {
       error(errSyntaxError, -1, "FormFieldText:: invalid DA object\n");
-      deleteGooList(daToks, GooString);
+      deleteGooList<GooString>(daToks);
       return;
     }
     if (defaultAppearance)
@@ -1251,7 +1251,7 @@ void FormFieldText::setTextFontSize(int fontSize)
         defaultAppearance->append(static_cast<GooString*>(daToks->get(i)));
       }
     }
-    deleteGooList(daToks, GooString);
+    deleteGooList<GooString>(daToks);
     obj.dictSet("DA", Object(defaultAppearance->copy()));
     xref->setModifiedObject(&obj, ref);
     updateChildrenAppearance();
diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index 634e5731..81c1244f 100644
--- a/poppler/GfxState.cc
+++ b/poppler/GfxState.cc
@@ -2968,7 +2968,7 @@ GfxDeviceNColorSpace::~GfxDeviceNColorSpace() {
   }
   delete alt;
   delete func;
-  deleteGooList(sepsCS, GfxSeparationColorSpace);
+  deleteGooList<GfxSeparationColorSpace>(sepsCS);
   if (mapping != nullptr)
     gfree(mapping);
 }
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index b07781ff..9a61c733 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -257,7 +257,7 @@ SysFontList::SysFontList() {
 }
 
 SysFontList::~SysFontList() {
-  deleteGooList(fonts, SysFontInfo);
+  deleteGooList<SysFontInfo>(fonts);
 }
 
 SysFontInfo *SysFontList::find(const GooString *name, GBool fixedWidth, GBool exact) {
@@ -558,7 +558,7 @@ GlobalParams::~GlobalParams() {
 
   delete nameToUnicodeZapfDingbats;
   delete nameToUnicodeText;
-  deleteGooList(toUnicodeDirs, GooString);
+  deleteGooList<GooString>(toUnicodeDirs);
   delete sysFonts;
   delete textEncoding;
 
diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc
index 60c1c183..89c8123a 100644
--- a/poppler/JBIG2Stream.cc
+++ b/poppler/JBIG2Stream.cc
@@ -1275,11 +1275,11 @@ void JBIG2Stream::close() {
     pageBitmap = nullptr;
   }
   if (segments) {
-    deleteGooList(segments, JBIG2Segment);
+    deleteGooList<JBIG2Segment>(segments);
     segments = nullptr;
   }
   if (globalSegments) {
-    deleteGooList(globalSegments, JBIG2Segment);
+    deleteGooList<JBIG2Segment>(globalSegments);
     globalSegments = nullptr;
   }
   dataPtr = dataEnd = nullptr;
diff --git a/poppler/Link.cc b/poppler/Link.cc
index f88183f9..0758428b 100644
--- a/poppler/Link.cc
+++ b/poppler/Link.cc
@@ -57,7 +57,7 @@ LinkAction::LinkAction() : nextActionList(nullptr) {
 
 LinkAction::~LinkAction() {
   if (nextActionList)
-    deleteGooList(nextActionList, LinkAction);
+    deleteGooList<LinkAction>(nextActionList);
 }
 
 LinkAction *LinkAction::parseDest(const Object *obj) {
@@ -880,12 +880,12 @@ LinkOCGState::LinkOCGState(const Object *obj) {
 
 LinkOCGState::~LinkOCGState() {
   if (stateList)
-    deleteGooList(stateList, StateList);
+    deleteGooList<StateList>(stateList);
 }
 
 LinkOCGState::StateList::~StateList() {
   if (list)
-    deleteGooList(list, Ref);
+    deleteGooList<Ref>(list);
 }
 
 //------------------------------------------------------------------------
diff --git a/poppler/OptionalContent.cc b/poppler/OptionalContent.cc
index 717dc33d..b197ac28 100644
--- a/poppler/OptionalContent.cc
+++ b/poppler/OptionalContent.cc
@@ -460,7 +460,7 @@ GooList *OCDisplayNode::takeChildren() {
 OCDisplayNode::~OCDisplayNode() {
   gfree(name);
   if (children) {
-    deleteGooList(children, OCDisplayNode);
+    deleteGooList<OCDisplayNode>(children);
   }
 }
 
diff --git a/poppler/Outline.cc b/poppler/Outline.cc
index c6b12dc0..6cb5d258 100644
--- a/poppler/Outline.cc
+++ b/poppler/Outline.cc
@@ -53,7 +53,7 @@ Outline::Outline(const Object *outlineObj, XRef *xref) {
 
 Outline::~Outline() {
   if (items) {
-    deleteGooList(items, OutlineItem);
+    deleteGooList<OutlineItem>(items);
   }
 }
 
@@ -156,7 +156,7 @@ void OutlineItem::open() {
 
 void OutlineItem::close() {
   if (kids) {
-    deleteGooList(kids, OutlineItem);
+    deleteGooList<OutlineItem>(kids);
     kids = nullptr;
   }
 }
diff --git a/poppler/PDFDocFactory.cc b/poppler/PDFDocFactory.cc
index ded56e97..9e9c510b 100644
--- a/poppler/PDFDocFactory.cc
+++ b/poppler/PDFDocFactory.cc
@@ -45,7 +45,7 @@ PDFDocFactory::PDFDocFactory(GooList *pdfDocBuilders)
 PDFDocFactory::~PDFDocFactory()
 {
   if (builders) {
-    deleteGooList(builders, PDFDocBuilder);
+    deleteGooList<PDFDocBuilder>(builders);
   }
 }
 
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 5d106c96..d54c45f1 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -1489,7 +1489,7 @@ PSOutputDev::~PSOutputDev() {
 #endif
   }
   if (paperSizes) {
-    deleteGooList(paperSizes, PSOutPaperSize);
+    deleteGooList<PSOutPaperSize>(paperSizes);
   }
   if (embFontList) {
     delete embFontList;
diff --git a/poppler/TextOutputDev.cc b/poppler/TextOutputDev.cc
index 0e4ab3b8..9402adbe 100644
--- a/poppler/TextOutputDev.cc
+++ b/poppler/TextOutputDev.cc
@@ -2378,8 +2378,8 @@ TextPage::~TextPage() {
     }
   }
   delete fonts;
-  deleteGooList(underlines, TextUnderline);
-  deleteGooList(links, TextLink);
+  deleteGooList<TextUnderline>(underlines);
+  deleteGooList<TextLink>(links);
 }
 
 void TextPage::incRefCnt() {
@@ -2433,9 +2433,9 @@ void TextPage::clear() {
     }
     gfree(blocks);
   }
-  deleteGooList(fonts, TextFontInfo);
-  deleteGooList(underlines, TextUnderline);
-  deleteGooList(links, TextLink);
+  deleteGooList<TextFontInfo>(fonts);
+  deleteGooList<TextUnderline>(underlines);
+  deleteGooList<TextLink>(links);
 
   curWord = nullptr;
   charPos = 0;
@@ -4381,7 +4381,7 @@ TextSelectionDumper::TextSelectionDumper(TextPage *page)
 TextSelectionDumper::~TextSelectionDumper()
 {
   for (int i = 0; i < nLines; i++)
-    deleteGooList(lines[i], TextWordSelection);
+    deleteGooList<TextWordSelection>(lines[i]);
   gfree(lines);
 }
 
@@ -4617,7 +4617,7 @@ TextSelectionPainter::TextSelectionPainter(TextPage *page,
 
 TextSelectionPainter::~TextSelectionPainter()
 {
-  deleteGooList(selectionList, TextWordSelection);
+  deleteGooList<TextWordSelection>(selectionList);
   delete state;
 }
 
diff --git a/qt5/src/poppler-fontinfo.cc b/qt5/src/poppler-fontinfo.cc
index dbc52922..954017c9 100644
--- a/qt5/src/poppler-fontinfo.cc
+++ b/qt5/src/poppler-fontinfo.cc
@@ -133,7 +133,7 @@ QList<FontInfo> FontIterator::next()
 	for ( int i = 0; i < items->getLength(); ++i ) {
 		fonts.append( FontInfo( FontInfoData( ( ::FontInfo* )items->get( i ) ) ) );
 	}
-	deleteGooList( items, ::FontInfo );
+	deleteGooList<::FontInfo>( items );
 	return fonts;
 }
 
diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc
index bab5123b..84add457 100644
--- a/splash/SplashBitmap.cc
+++ b/splash/SplashBitmap.cc
@@ -161,7 +161,7 @@ SplashBitmap::~SplashBitmap() {
     }
   }
   gfree(alpha);
-  deleteGooList(separationList, GfxSeparationColorSpace);
+  deleteGooList<GfxSeparationColorSpace>(separationList);
 }
 
 
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index ef8c65d0..4cd7b9fd 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -302,7 +302,7 @@ HtmlPage::~HtmlPage() {
   delete fonts;
   delete links;
   delete imgExt;
-  deleteGooList(imgList, HtmlImage);
+  deleteGooList<HtmlImage>(imgList);
 }
 
 void HtmlPage::updateFont(GfxState *state) {
@@ -1230,7 +1230,7 @@ HtmlOutputDev::~HtmlOutputDev() {
     delete Docname;
     delete docTitle;
 
-    deleteGooList(glMetaVars, HtmlMetaVar);
+    deleteGooList<HtmlMetaVar>(glMetaVars);
 
     if (fContentsFrame){
       fputs("</body>\n</html>\n",fContentsFrame);  
diff --git a/utils/pdfdetach.cc b/utils/pdfdetach.cc
index c8936997..860b55c2 100644
--- a/utils/pdfdetach.cc
+++ b/utils/pdfdetach.cc
@@ -308,7 +308,7 @@ int main(int argc, char *argv[]) {
   // clean up
  err2:
   if (embeddedFiles)
-    deleteGooList(embeddedFiles, FileSpec);
+    deleteGooList<FileSpec>(embeddedFiles);
   uMap->decRefCnt();
   delete doc;
  err1:
commit 46a8486d71b686facdea716bd04911bd029ac67e
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Sun Aug 26 21:31:18 2018 +0200

    Remove GooList::insert since the single caller actually needs only std::vector::push_back.

diff --git a/goo/GooList.h b/goo/GooList.h
index ac642f88..d2d14df6 100644
--- a/goo/GooList.h
+++ b/goo/GooList.h
@@ -72,12 +72,6 @@ struct GooList : public std::vector<void *> {
     reserve(size() + list->size());
     static_cast<std::vector<void *>&>(*this).insert(end(), list->begin(), list->end());
   }
-
-  // Insert an element at index <i>.
-  // Assumes 0 <= i <= length.
-  void insert(int i, void *p) {
-    static_cast<std::vector<void *>&>(*this).insert(begin() + i, p);
-  }
 };
 
 #define deleteGooList(list, T)                        \
diff --git a/poppler/PDFDocFactory.cc b/poppler/PDFDocFactory.cc
index cbd1395f..ded56e97 100644
--- a/poppler/PDFDocFactory.cc
+++ b/poppler/PDFDocFactory.cc
@@ -35,11 +35,11 @@ PDFDocFactory::PDFDocFactory(GooList *pdfDocBuilders)
   } else {
     builders = new GooList();
   }
+  builders->push_back(new LocalPDFDocBuilder());
+  builders->push_back(new StdinPDFDocBuilder());
 #ifdef ENABLE_LIBCURL
-  builders->insert(0, new CurlPDFDocBuilder());
+  builders->push_back(new CurlPDFDocBuilder());
 #endif
-  builders->insert(0, new StdinPDFDocBuilder());
-  builders->insert(0, new LocalPDFDocBuilder());
 }
 
 PDFDocFactory::~PDFDocFactory()
commit 76c716c7d65f5110bd3e2eec25aed62aed7fe24a
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Sun Aug 26 21:25:35 2018 +0200

    Remove GooList::copy since it is apparently unused.

diff --git a/goo/GooList.h b/goo/GooList.h
index c0e71023..ac642f88 100644
--- a/goo/GooList.h
+++ b/goo/GooList.h
@@ -52,9 +52,6 @@ struct GooList : public std::vector<void *> {
   // Get the number of elements.
   int getLength() const { return size(); }
 
-  // Returns a (shallow) copy of this list.
-  GooList *copy() const { return new GooList(static_cast<const std::vector<void *>&>(*this)); }
-
   //----- ordered list support
 
   // Return the <i>th element.
commit 4ae24db322e38ec81acc749c71c9efa972afe39d
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Sun Aug 26 21:20:57 2018 +0200

    Remove GooList::del since its few users are easily converted.

diff --git a/goo/GooList.h b/goo/GooList.h
index 657839a5..c0e71023 100644
--- a/goo/GooList.h
+++ b/goo/GooList.h
@@ -81,15 +81,6 @@ struct GooList : public std::vector<void *> {
   void insert(int i, void *p) {
     static_cast<std::vector<void *>&>(*this).insert(begin() + i, p);
   }
-
-  // Deletes and returns the element at index <i>.
-  // Assumes 0 <= i < length.
-  void *del(int i) {
-    auto iter = begin() + i;
-    auto tmp = *iter;
-    erase(iter);
-    return tmp;
-  }
 };
 
 #define deleteGooList(list, T)                        \
diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc
index 2acbc915..60c1c183 100644
--- a/poppler/JBIG2Stream.cc
+++ b/poppler/JBIG2Stream.cc
@@ -4177,20 +4177,17 @@ JBIG2Segment *JBIG2Stream::findSegment(Guint segNum) {
 }
 
 void JBIG2Stream::discardSegment(Guint segNum) {
-  JBIG2Segment *seg;
-  int i;
-
-  for (i = 0; i < globalSegments->getLength(); ++i) {
-    seg = (JBIG2Segment *)globalSegments->get(i);
+  for (auto it = globalSegments->begin(); it != globalSegments->end(); ++it) {
+    auto seg = static_cast<JBIG2Segment *>(*it);
     if (seg->getSegNum() == segNum) {
-      globalSegments->del(i);
+      globalSegments->erase(it);
       return;
     }
   }
-  for (i = 0; i < segments->getLength(); ++i) {
-    seg = (JBIG2Segment *)segments->get(i);
+  for (auto it = segments->begin(); it != segments->end(); ++it) {
+    auto seg = static_cast<JBIG2Segment *>(*it);
     if (seg->getSegNum() == segNum) {
-      segments->del(i);
+      segments->erase(it);
       return;
     }
   }
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index bcef5f18..ef8c65d0 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -757,10 +757,9 @@ void HtmlPage::dumpAsXML(FILE* f,int page){
     fprintf(f,"\t%s\n",fontCSStyle->getCString());
     delete fontCSStyle;
   }
-  
-  int listlen=imgList->getLength();
-  for (int i = 0; i < listlen; i++) {
-    HtmlImage *img = (HtmlImage*)imgList->del(0);
+
+  for (auto ptr : *imgList) {
+    auto img = static_cast<HtmlImage *>(ptr);
     if (!noRoundedCoordinates) {
       fprintf(f, "<image top=\"%d\" left=\"%d\" ", xoutRound(img->yMin), xoutRound(img->xMin));
       fprintf(f, "width=\"%d\" height=\"%d\" ", xoutRound(img->xMax - img->xMin), xoutRound(img->yMax - img->yMin));
@@ -772,6 +771,7 @@ void HtmlPage::dumpAsXML(FILE* f,int page){
     fprintf(f,"src=\"%s\"/>\n",img->fName->getCString());
     delete img;
   }
+  imgList->clear();
 
   for(HtmlString *tmp=yxStrings;tmp;tmp=tmp->yxNext){
     if (tmp->htext){
@@ -952,9 +952,8 @@ void HtmlPage::dump(FILE *f, int pageNum)
   {
     fprintf(f,"<a name=%d></a>",pageNum);
     // Loop over the list of image names on this page
-    int listlen=imgList->getLength();
-    for (int i = 0; i < listlen; i++) {
-      HtmlImage *img = (HtmlImage*)imgList->del(0);
+    for (auto ptr : *imgList) {
+      auto img = static_cast<HtmlImage *>(ptr);
 
       // see printCSS() for class names
       const char *styles[4] = { "", " class=\"xflip\"", " class=\"yflip\"", " class=\"xyflip\"" };
@@ -965,6 +964,7 @@ void HtmlPage::dump(FILE *f, int pageNum)
       fprintf(f,"<img%s src=\"%s\"/><br/>\n",styles[style_index],img->fName->getCString());
       delete img;
     }
+    imgList->clear();
 
     GooString* str;
     for(HtmlString *tmp=yxStrings;tmp;tmp=tmp->yxNext){
commit 4236d98179699dd7512805075eecb292fc253965
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Sun Aug 26 16:30:28 2018 +0200

    Reimplement GooList as a subtype of std::vector
    
    This reimplements GooList as a subtype of std::vector<void *> to facilitate
    porting the various places where GooList is used to STL containers. After this
    change, this can happen mechanically by replacing all of the GooList-specific
    API by their implementations at the call sites and cleaning up until at some
    point no more GooList-specific API is left and the type can be removed.
    
    This of course keeps the normally inefficient pattern of storing pointer to
    objects instead of objects inside these containers which however can then be
    refactoring in a separate step building on top this and as a pure optimization.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fdf6fb45..72ee5483 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -311,7 +311,6 @@ configure_file(poppler/poppler-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/popple
 
 set(poppler_SRCS
   goo/gfile.cc
-  goo/GooList.cc
   goo/GooTimer.cc
   goo/GooString.cc
   goo/FixedPoint.cc
diff --git a/goo/GooList.cc b/goo/GooList.cc
deleted file mode 100644
index e0e4875b..00000000
--- a/goo/GooList.cc
+++ /dev/null
@@ -1,136 +0,0 @@
-//========================================================================
-//
-// GooList.cc
-//
-// Copyright 2001-2003 Glyph & Cog, LLC
-//
-//========================================================================
-
-//========================================================================
-//
-// Modified under the Poppler project - http://poppler.freedesktop.org
-//
-// All changes made under the Poppler project to this file are licensed
-// under GPL version 2 or later
-//
-// Copyright (C) 2018 Albert Astals Cid <aacid at kde.org>
-//
-// To see a description of the changes please see the Changelog file that
-// came with your tarball or type make ChangeLog if you are building from git
-//
-//========================================================================
-
-#include <config.h>
-
-#ifdef USE_GCC_PRAGMAS
-#pragma implementation
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include "gmem.h"
-#include "GooList.h"
-
-//------------------------------------------------------------------------
-// GooList
-//------------------------------------------------------------------------
-
-GooList::GooList() {
-  size = 8;
-  data = (void **)gmallocn(size, sizeof(void*));
-  length = 0;
-  inc = 0;
-}
-
-GooList::GooList(int sizeA) {
-  size = sizeA ? sizeA : 8;
-  data = (void **)gmallocn(size, sizeof(void*));
-  length = 0;
-  inc = 0;
-}
-
-GooList::~GooList() {
-  gfree(data);
-}
-
-GooList *GooList::copy() const {
-  GooList *ret;
-
-  ret = new GooList(length);
-  ret->length = length;
-  memcpy(ret->data, data, length * sizeof(void *));
-  ret->inc = inc;
-  return ret;
-}
-
-void GooList::append(void *p) {
-  if (length >= size) {
-    expand();
-  }
-  data[length++] = p;
-}
-
-void GooList::append(GooList *list) {
-  int i;
-
-  while (length + list->length > size) {
-    expand();
-  }
-  for (i = 0; i < list->length; ++i) {
-    data[length++] = list->data[i];
-  }
-}
-
-void GooList::insert(int i, void *p) {
-  if (length >= size) {
-    expand();
-  }
-  if (i < 0) {
-    i = 0;
-  }
-  if (i < length) {
-    memmove(data+i+1, data+i, (length - i) * sizeof(void *));
-  }
-  data[i] = p;
-  ++length;
-}
-
-void *GooList::del(int i) {
-  void *p;
-
-  p = data[i];
-  if (i < length - 1) {
-    memmove(data+i, data+i+1, (length - i - 1) * sizeof(void *));
-  }
-  --length;
-  if (size - length >= ((inc > 0) ? inc : size/2)) {
-    shrink();
-  }
-  return p;
-}
-
-void GooList::sort(int (*cmp)(const void *obj1, const void *obj2)) {
-  qsort(data, length, sizeof(void *), cmp);
-}
-
-void GooList::reverse() {
-  void *t;
-  int n, i;
-
-  n = length / 2;
-  for (i = 0; i < n; ++i) {
-    t = data[i];
-    data[i] = data[length - 1 - i];
-    data[length - 1 - i] = t;
-  }
-}
-
-void GooList::expand() {
-  size += (inc > 0) ? inc : size;
-  data = (void **)greallocn(data, size, sizeof(void*));
-}
-
-void GooList::shrink() {
-  size -= (inc > 0) ? inc : size/2;
-  data = (void **)greallocn(data, size, sizeof(void*));
-}
diff --git a/goo/GooList.h b/goo/GooList.h
index a0bc525d..657839a5 100644
--- a/goo/GooList.h
+++ b/goo/GooList.h
@@ -20,89 +20,76 @@
 //
 //========================================================================
 
-#ifndef GLIST_H
-#define GLIST_H
+#pragma once
 
-#ifdef USE_GCC_PRAGMAS
-#pragma interface
-#endif
-
-#include "gtypes.h"
+#include <algorithm>
+#include <vector>
 
 //------------------------------------------------------------------------
 // GooList
 //------------------------------------------------------------------------
 
-class GooList {
-public:
+struct GooList : public std::vector<void *> {
 
   // Create an empty list.
-  GooList();
+  GooList() = default;
+
+  // Create an empty list with space for <size> elements.
+  explicit GooList(int size) : std::vector<void *>(size) {}
+
+  // Movable but not copyable
+  GooList(GooList &&other) = default;
+  GooList& operator=(GooList &&other) = default;
 
-  // Create an empty list with space for <size1> elements.
-  GooList(int sizeA);
+  GooList(const GooList &other) = delete;
+  GooList& operator=(const GooList &other) = delete;
 
-  // Destructor - does not free pointed-to objects.
-  ~GooList();
+  explicit GooList(const std::vector<void *>& vec) : std::vector<void *>(vec) {}
+  explicit GooList(std::vector<void *>&& vec) : std::vector<void *>(std::move(vec)) {}
 
   //----- general
 
   // Get the number of elements.
-  int getLength() const { return length; }
+  int getLength() const { return size(); }
 
   // Returns a (shallow) copy of this list.
-  GooList *copy() const;
+  GooList *copy() const { return new GooList(static_cast<const std::vector<void *>&>(*this)); }
 
   //----- ordered list support
 
   // Return the <i>th element.
   // Assumes 0 <= i < length.
-  void *get(int i) const { return data[i]; }
+  void *get(int i) const { return (*this)[i]; }
 
   // Replace the <i>th element.
   // Assumes 0 <= i < length.
-  void put(int i, void *p) { data[i] = p; }
+  void put(int i, void *p) { (*this)[i] = p; }
 
   // Append an element to the end of the list.
-  void append(void *p);
+  void append(void *p) {
+    push_back(p);
+  }
 
   // Append another list to the end of this one.
-  void append(GooList *list);
+  void append(GooList *list) {
+    reserve(size() + list->size());
+    static_cast<std::vector<void *>&>(*this).insert(end(), list->begin(), list->end());
+  }
 
   // Insert an element at index <i>.
   // Assumes 0 <= i <= length.
-  void insert(int i, void *p);
+  void insert(int i, void *p) {
+    static_cast<std::vector<void *>&>(*this).insert(begin() + i, p);
+  }
 
   // Deletes and returns the element at index <i>.
   // Assumes 0 <= i < length.
-  void *del(int i);
-
-  // Sort the list accoring to the given comparison function.
-  // NB: this sorts an array of pointers, so the pointer args need to
-  // be double-dereferenced.
-  void sort(int (*cmp)(const void *ptr1, const void *ptr2));
-
-  // Reverse the list.
-  void reverse();
-
-  //----- control
-
-  // Set allocation increment to <inc>.  If inc > 0, that many
-  // elements will be allocated every time the list is expanded.
-  // If inc <= 0, the list will be doubled in size.
-  void setAllocIncr(int incA) { inc = incA; }
-
-private:
-  GooList(const GooList &other);
-  GooList& operator=(const GooList &other);
-
-  void expand();
-  void shrink();
-
-  void **data;			// the list elements
-  int size;			// size of data array
-  int length;			// number of elements on list
-  int inc;			// allocation increment
+  void *del(int i) {
+    auto iter = begin() + i;
+    auto tmp = *iter;
+    erase(iter);
+    return tmp;
+  }
 };
 
 #define deleteGooList(list, T)                        \
@@ -116,5 +103,3 @@ private:
       delete _list;                                 \
     }                                               \
   } while (0)
-
-#endif
diff --git a/utils/printencodings.cc b/utils/printencodings.cc
index 2c098b4b..8e4669ee 100644
--- a/utils/printencodings.cc
+++ b/utils/printencodings.cc
@@ -23,22 +23,19 @@
 #include "goo/GooList.h"
 #include "goo/GooString.h"
 
-
-static int cmpGooString(const void *ptr1, const void *ptr2)
-{
-  GooString *s1 = *((GooString **)ptr1);
-  GooString *s2 = *((GooString **)ptr2);
-  return s1->cmp(s2);
-}
-
 void printEncodings()
 {
   GooList *encNames = globalParams->getEncodingNames();
-  encNames->sort(cmpGooString);
+
+  std::sort(encNames->begin(), encNames->end(), [](void *lhs, void *rhs) {
+    return static_cast<GooString *>(lhs)->cmp(static_cast<GooString *>(rhs)) < 0;
+  });
+
   printf("Available encodings are:\n");
   for (int i = 0; i < encNames->getLength(); ++i) {
     GooString *enc = (GooString*)encNames->get(i);
     printf("%s\n", enc->getCString());
   }
+
   delete encNames;
 }


More information about the poppler mailing list