Hello,

the attached patch replaced Poppler's internal hash table implementation
GooHash by std::unordered_map found in the C++ standard library since
C++11. This continues Poppler's slow drift towards standard library
containers and removes one of the home-grown data structures with the
main goals of reducing code size and improving the long term
maintainability of the code base.

Best regards, Adam.
From b188737a772b8281cac92b2fd5cdab8c9e49afe9 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 18 Feb 2018 16:10:16 +0100
Subject: [PATCH 1/6] Replace GooHash by std::unordered_map in FoFiTrueType.

---
 fofi/FoFiTrueType.cc | 38 ++++++++++++++------------------------
 fofi/FoFiTrueType.h  |  7 ++++---
 2 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/fofi/FoFiTrueType.cc b/fofi/FoFiTrueType.cc
index 76299acc..29bd7878 100644
--- a/fofi/FoFiTrueType.cc
+++ b/fofi/FoFiTrueType.cc
@@ -43,7 +43,6 @@
 #include "goo/gmem.h"
 #include "goo/GooLikely.h"
 #include "goo/GooString.h"
-#include "goo/GooHash.h"
 #include "FoFiType1C.h"
 #include "FoFiTrueType.h"
 #include "poppler/Error.h"
@@ -305,7 +304,6 @@ FoFiTrueType::FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceI
   nTables = 0;
   cmaps = nullptr;
   nCmaps = 0;
-  nameToGID = nullptr;
   parsedOk = gFalse;
   faceIndex = faceIndexA;
   gsubFeatureTable = 0;
@@ -317,9 +315,6 @@ FoFiTrueType::FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceI
 FoFiTrueType::~FoFiTrueType() {
   gfree(tables);
   gfree(cmaps);
-  if (nameToGID) {
-    delete nameToGID;
-  }
 }
 
 int FoFiTrueType::getNumCmaps() {
@@ -442,11 +437,12 @@ int FoFiTrueType::mapCodeToGID(int i, Guint c) {
   return gid;
 }
 
-int FoFiTrueType::mapNameToGID(char *name) {
-  if (!nameToGID) {
+int FoFiTrueType::mapNameToGID(char *name) const {
+  const auto gid = nameToGID.find(name);
+  if (gid == nameToGID.end()) {
     return 0;
   }
-  return nameToGID->lookupInt(name);
+  return gid->second;
 }
 
 GBool FoFiTrueType::getCFFBlock(char **start, int *length) {
@@ -1450,7 +1446,7 @@ void FoFiTrueType::parse() {
 }
 
 void FoFiTrueType::readPostTable() {
-  GooString *name;
+  std::string name;
   int tablePos, postFmt, stringIdx, stringPos;
   GBool ok;
   int i, j, n, m;
@@ -1465,12 +1461,12 @@ void FoFiTrueType::readPostTable() {
     goto err;
   }
   if (postFmt == 0x00010000) {
-    nameToGID = new GooHash(gTrue);
+    nameToGID.reserve(258);
     for (i = 0; i < 258; ++i) {
-      nameToGID->add(new GooString(macGlyphNames[i]), i);
+      nameToGID.emplace(macGlyphNames[i], i);
     }
   } else if (postFmt == 0x00020000) {
-    nameToGID = new GooHash(gTrue);
+    nameToGID.reserve(258);
     n = getU16BE(tablePos + 32, &ok);
     if (!ok) {
       goto err;
@@ -1484,8 +1480,7 @@ void FoFiTrueType::readPostTable() {
       ok = gTrue;
       j = getU16BE(tablePos + 34 + 2*i, &ok);
       if (j < 258) {
-	nameToGID->removeInt(macGlyphNames[j]);
-	nameToGID->add(new GooString(macGlyphNames[j]), i);
+          nameToGID[macGlyphNames[j]] = i;
       } else {
 	j -= 258;
 	if (j != stringIdx) {
@@ -1500,23 +1495,21 @@ void FoFiTrueType::readPostTable() {
 	if (!ok || !checkRegion(stringPos + 1, m)) {
 	  continue;
 	}
-	name = new GooString((char *)&file[stringPos + 1], m);
-	nameToGID->removeInt(name);
-	nameToGID->add(name, i);
+    name.assign((char *)&file[stringPos + 1], m);
+    nameToGID[name] = i;
 	++stringIdx;
 	stringPos += 1 + m;
       }
     }
   } else if (postFmt == 0x00028000) {
-    nameToGID = new GooHash(gTrue);
+    nameToGID.reserve(258);
     for (i = 0; i < nGlyphs; ++i) {
       j = getU8(tablePos + 32 + i, &ok);
       if (!ok) {
 	continue;
       }
       if (j < 258) {
-	nameToGID->removeInt(macGlyphNames[j]);
-	nameToGID->add(new GooString(macGlyphNames[j]), i);
+          nameToGID[macGlyphNames[j]] = i;
       }
     }
   }
@@ -1524,10 +1517,7 @@ void FoFiTrueType::readPostTable() {
   return;
 
  err:
-  if (nameToGID) {
-    delete nameToGID;
-    nameToGID = nullptr;
-  }
+  nameToGID.clear();
 }
 
 int FoFiTrueType::seekTable(const char *tag) {
diff --git a/fofi/FoFiTrueType.h b/fofi/FoFiTrueType.h
index 0c42c837..432fe4bb 100644
--- a/fofi/FoFiTrueType.h
+++ b/fofi/FoFiTrueType.h
@@ -32,11 +32,12 @@
 #endif
 
 #include "stddef.h"
+#include <unordered_map>
+#include <string>
 #include "goo/gtypes.h"
 #include "FoFiBase.h"
 
 class GooString;
-class GooHash;
 struct TrueTypeTable;
 struct TrueTypeCmap;
 
@@ -82,7 +83,7 @@ public:
   // Returns the GID corresponding to <name> according to the post
   // table.  Returns 0 if there is no mapping for <name> or if the
   // font does not have a post table.
-  int mapNameToGID(char *name);
+  int mapNameToGID(char *name) const;
 
   // Return the mapping from CIDs to GIDs, and return the number of
   // CIDs in *<nCIDs>.  This is only useful for CID fonts.  (Only
@@ -199,7 +200,7 @@ private:
   int nGlyphs;
   int locaFmt;
   int bbox[4];
-  GooHash *nameToGID;
+  std::unordered_map<std::string,int> nameToGID;
   GBool openTypeCFF;
 
   GBool parsedOk;
-- 
2.16.1


From 30f1a7483180bf2425e1a9b5570fa430db2b1c65 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 18 Feb 2018 16:10:59 +0100
Subject: [PATCH 2/6] Replace GooHash by std::unordered_map in GlobalParams.

---
 poppler/CharCodeToUnicode.cc |   8 +-
 poppler/CharCodeToUnicode.h  |   4 +-
 poppler/GlobalParams.cc      | 219 ++++++++++++++-----------------------------
 poppler/GlobalParams.h       |  33 +++----
 4 files changed, 95 insertions(+), 169 deletions(-)

diff --git a/poppler/CharCodeToUnicode.cc b/poppler/CharCodeToUnicode.cc
index 17df0292..a5fbe0c3 100644
--- a/poppler/CharCodeToUnicode.cc
+++ b/poppler/CharCodeToUnicode.cc
@@ -125,7 +125,7 @@ CharCodeToUnicode *CharCodeToUnicode::makeIdentityMapping() {
   return ctu;
 }
 
-CharCodeToUnicode *CharCodeToUnicode::parseCIDToUnicode(GooString *fileName,
+CharCodeToUnicode *CharCodeToUnicode::parseCIDToUnicode(const char *fileName,
 							GooString *collection) {
   FILE *f;
   Unicode *mapA;
@@ -134,8 +134,8 @@ CharCodeToUnicode *CharCodeToUnicode::parseCIDToUnicode(GooString *fileName,
   Unicode u;
   CharCodeToUnicode *ctu;
 
-  if (!(f = openFile(fileName->getCString(), "r"))) {
-    error(errIO, -1, "Couldn't open cidToUnicode file '{0:t}'",
+  if (!(f = openFile(fileName, "r"))) {
+    error(errIO, -1, "Couldn't open cidToUnicode file '{0:s}'",
 	  fileName);
     return nullptr;
   }
@@ -152,7 +152,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseCIDToUnicode(GooString *fileName,
     if (sscanf(buf, "%x", &u) == 1) {
       mapA[mapLenA] = u;
     } else {
-      error(errSyntaxWarning, -1, "Bad line ({0:d}) in cidToUnicode file '{1:t}'",
+      error(errSyntaxWarning, -1, "Bad line ({0:d}) in cidToUnicode file '{1:s}'",
 	    (int)(mapLenA + 1), fileName);
       mapA[mapLenA] = 0;
     }
diff --git a/poppler/CharCodeToUnicode.h b/poppler/CharCodeToUnicode.h
index 13572217..6c92cae9 100644
--- a/poppler/CharCodeToUnicode.h
+++ b/poppler/CharCodeToUnicode.h
@@ -55,8 +55,8 @@ public:
   // Read the CID-to-Unicode mapping for <collection> from the file
   // specified by <fileName>.  Sets the initial reference count to 1.
   // Returns NULL on failure.
-  static CharCodeToUnicode *parseCIDToUnicode(GooString *fileName,
-					      GooString *collection);
+  static CharCodeToUnicode *parseCIDToUnicode(const char *fileName,
+                          GooString *collection);
 
   // Create a Unicode-to-Unicode mapping from the file specified by
   // <fileName>.  Sets the initial reference count to 1.  Returns NULL
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 50b7eee2..a2def055 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -65,7 +65,6 @@
 #include "goo/gmem.h"
 #include "goo/GooString.h"
 #include "goo/GooList.h"
-#include "goo/GooHash.h"
 #include "goo/gfile.h"
 #include "Error.h"
 #include "NameToCharCode.h"
@@ -548,9 +547,6 @@ Plugin::~Plugin() {
 GlobalParams::GlobalParams(const char *customPopplerDataDir)
   : popplerDataDir(customPopplerDataDir)
 {
-  UnicodeMap *map;
-  int i;
-
 #ifdef MULTITHREADED
   gInitMutex(&mutex);
   gInitMutex(&unicodeMapCacheMutex);
@@ -562,7 +558,7 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir)
   // scan the encoding in reverse because we want the lowest-numbered
   // index for each char name ('space' is encoded twice)
   macRomanReverseMap = new NameToCharCode();
-  for (i = 255; i >= 0; --i) {
+  for (int i = 255; i >= 0; --i) {
     if (macRomanEncoding[i]) {
       macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
     }
@@ -573,13 +569,7 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir)
 #endif
   nameToUnicodeZapfDingbats = new NameToCharCode();
   nameToUnicodeText = new NameToCharCode();
-  cidToUnicodes = new GooHash(gTrue);
-  unicodeToUnicodes = new GooHash(gTrue);
-  residentUnicodeMaps = new GooHash();
-  unicodeMaps = new GooHash(gTrue);
-  cMapDirs = new GooHash(gTrue);
   toUnicodeDirs = new GooList();
-  fontFiles = new GooHash(gTrue);
   sysFonts = new SysFontList();
   psExpandSmaller = gFalse;
   psShrinkLarger = gTrue;
@@ -612,31 +602,39 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir)
 #endif
 
   // set up the initial nameToUnicode tables
-  for (i = 0; nameToUnicodeZapfDingbatsTab[i].name; ++i) {
+  for (int i = 0; nameToUnicodeZapfDingbatsTab[i].name; ++i) {
     nameToUnicodeZapfDingbats->add(nameToUnicodeZapfDingbatsTab[i].name, nameToUnicodeZapfDingbatsTab[i].u);
   }
 
-  for (i = 0; nameToUnicodeTextTab[i].name; ++i) {
+  for (int i = 0; nameToUnicodeTextTab[i].name; ++i) {
     nameToUnicodeText->add(nameToUnicodeTextTab[i].name, nameToUnicodeTextTab[i].u);
   }
 
   // set up the residentUnicodeMaps table
-  map = new UnicodeMap("Latin1", gFalse,
-		       latin1UnicodeMapRanges, latin1UnicodeMapLen);
-  residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("ASCII7", gFalse,
-		       ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
-  residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("Symbol", gFalse,
-		       symbolUnicodeMapRanges, symbolUnicodeMapLen);
-  residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
-		       zapfDingbatsUnicodeMapLen);
-  residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
-  residentUnicodeMaps->add(map->getEncodingName(), map);
-  map = new UnicodeMap("UTF-16", gTrue, &mapUTF16);
-  residentUnicodeMaps->add(map->getEncodingName(), map);
+
+  const auto emplaceRangeMap = [&](const char* encodingName, GBool unicodeOut, UnicodeMapRange* ranges, int len) {
+    residentUnicodeMaps.emplace(
+      std::piecewise_construct,
+      std::forward_as_tuple(encodingName),
+      std::forward_as_tuple(encodingName, unicodeOut, ranges, len)
+    );
+  };
+
+  const auto emplaceFuncMap = [&](const char* encodingName, GBool unicodeOut, UnicodeMapFunc func) {
+    residentUnicodeMaps.emplace(
+      std::piecewise_construct,
+      std::forward_as_tuple(encodingName),
+      std::forward_as_tuple(encodingName, unicodeOut, func)
+    );
+  };
+
+  residentUnicodeMaps.reserve(6);
+  emplaceRangeMap("Latin1", gFalse, latin1UnicodeMapRanges, latin1UnicodeMapLen);
+  emplaceRangeMap("ASCII7", gFalse, ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
+  emplaceRangeMap("Symbol", gFalse, symbolUnicodeMapRanges, symbolUnicodeMapLen);
+  emplaceRangeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges, zapfDingbatsUnicodeMapLen);
+  emplaceFuncMap("UTF-8", gTrue, &mapUTF8);
+  emplaceFuncMap("UTF-16", gTrue, &mapUTF16);
 
   scanEncodingDirs();
 }
@@ -717,34 +715,16 @@ void GlobalParams::parseNameToUnicode(GooString *name) {
   fclose(f);
 }
 
-void GlobalParams::addCIDToUnicode(GooString *collection,
-				   GooString *fileName) {
-  GooString *old;
-
-  if ((old = (GooString *)cidToUnicodes->remove(collection))) {
-    delete old;
-  }
-  cidToUnicodes->add(collection->copy(), fileName->copy());
+void GlobalParams::addCIDToUnicode(GooString *collection, GooString *fileName) {
+  cidToUnicodes[collection->getCString()] = fileName->getCString();
 }
 
-void GlobalParams::addUnicodeMap(GooString *encodingName, GooString *fileName)
-{
-  GooString *old;
-
-  if ((old = (GooString *)unicodeMaps->remove(encodingName))) {
-    delete old;
-  }
-  unicodeMaps->add(encodingName->copy(), fileName->copy());
+void GlobalParams::addUnicodeMap(GooString *encodingName, GooString *fileName) {
+  unicodeMaps[encodingName->getCString()] = fileName->getCString();
 }
 
 void GlobalParams::addCMapDir(GooString *collection, GooString *dir) {
-  GooList *list;
-
-  if (!(list = (GooList *)cMapDirs->lookup(collection))) {
-    list = new GooList();
-    cMapDirs->add(collection->copy(), list);
-  }
-  list->append(dir->copy());
+  cMapDirs.emplace(collection->getCString(), dir->getCString());
 }
 
 GBool GlobalParams::parseYesNo2(const char *token, GBool *flag) {
@@ -765,28 +745,13 @@ GlobalParams::~GlobalParams() {
 
   delete nameToUnicodeZapfDingbats;
   delete nameToUnicodeText;
-  deleteGooHash(cidToUnicodes, GooString);
-  deleteGooHash(unicodeToUnicodes, GooString);
-  deleteGooHash(residentUnicodeMaps, UnicodeMap);
-  deleteGooHash(unicodeMaps, GooString);
   deleteGooList(toUnicodeDirs, GooString);
-  deleteGooHash(fontFiles, GooString);
 #ifdef _WIN32
   deleteGooHash(substFiles, GooString);
 #endif
   delete sysFonts;
   delete textEncoding;
 
-  GooHashIter *iter;
-  GooString *key;
-  cMapDirs->startIter(&iter);
-  void *val;
-  while (cMapDirs->getNext(&iter, &key, &val)) {
-    GooList* list = (GooList*)val;
-    deleteGooList(list, GooString);
-  }
-  delete cMapDirs;
-
   delete cidToUnicodeCache;
   delete unicodeToUnicodeCache;
   delete unicodeMapCache;
@@ -827,55 +792,48 @@ Unicode GlobalParams::mapNameToUnicodeText(const char *charName) {
 }
 
 UnicodeMap *GlobalParams::getResidentUnicodeMap(GooString *encodingName) {
-  UnicodeMap *map;
+  UnicodeMap *map = nullptr;
 
   lockGlobalParams;
-  map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
-  unlockGlobalParams;
-  if (map) {
-    map->incRefCnt();
+  const auto unicodeMap = residentUnicodeMaps.find(encodingName->getCString());
+  if (unicodeMap != residentUnicodeMaps.end()) {
+      map = &unicodeMap->second;
+      map->incRefCnt();
   }
+  unlockGlobalParams;
+
   return map;
 }
 
 FILE *GlobalParams::getUnicodeMapFile(GooString *encodingName) {
-  GooString *fileName;
-  FILE *f;
+  FILE *file = nullptr;
 
   lockGlobalParams;
-  if ((fileName = (GooString *)unicodeMaps->lookup(encodingName))) {
-    f = openFile(fileName->getCString(), "r");
-  } else {
-    f = nullptr;
+  const auto unicodeMap = unicodeMaps.find(encodingName->getCString());
+  if (unicodeMap != unicodeMaps.end()) {
+    file = openFile(unicodeMap->second.c_str(), "r");
   }
   unlockGlobalParams;
-  return f;
+
+  return file;
 }
 
 FILE *GlobalParams::findCMapFile(GooString *collection, GooString *cMapName) {
-  GooList *list;
-  GooString *dir;
-  GooString *fileName;
-  FILE *f;
-  int i;
+  FILE *file = nullptr;
 
   lockGlobalParams;
-  if (!(list = (GooList *)cMapDirs->lookup(collection))) {
-    unlockGlobalParams;
-    return nullptr;
-  }
-  for (i = 0; i < list->getLength(); ++i) {
-    dir = (GooString *)list->get(i);
-    fileName = appendToPath(dir->copy(), cMapName->getCString());
-    f = openFile(fileName->getCString(), "r");
-    delete fileName;
-    if (f) {
-      unlockGlobalParams;
-      return f;
+  const auto cMapDirs = this->cMapDirs.equal_range(collection->getCString());
+  for (auto cMapDir = cMapDirs.first; cMapDir != cMapDirs.second; ++cMapDir) {
+    auto* const path = new GooString(cMapDir->second.c_str());
+    appendToPath(path, cMapName->getCString());
+    file = openFile(path->getCString(), "r");
+    delete path;
+    if (file) {
+        break;
     }
   }
   unlockGlobalParams;
-  return nullptr;
+  return file;
 }
 
 FILE *GlobalParams::findToUnicodeFile(GooString *name) {
@@ -1072,17 +1030,16 @@ static FcPattern *buildFcPattern(GfxFont *font, GooString *base14Name)
 #endif
 
 GooString *GlobalParams::findFontFile(GooString *fontName) {
-  GooString *path;
+  GooString *path = nullptr;
 
   setupBaseFonts(nullptr);
   lockGlobalParams;
-  if ((path = (GooString *)fontFiles->lookup(fontName))) {
-    path = path->copy();
-    unlockGlobalParams;
-    return path;
+  const auto fontFile = fontFiles.find(fontName->getCString());
+  if (fontFile != fontFiles.end()) {
+    path = new GooString(fontFile->second.c_str());
   }
   unlockGlobalParams;
-  return nullptr;
+  return path;
 }
 
 /* if you can't or don't want to use Fontconfig, you need to implement
@@ -1090,7 +1047,7 @@ GooString *GlobalParams::findFontFile(GooString *fontName) {
 */
 #ifdef WITH_FONTCONFIGURATION_FONTCONFIG
 // not needed for fontconfig
-void GlobalParams::setupBaseFonts(char *dir) {
+void GlobalParams::setupBaseFonts(char *) {
 }
 
 GooString *GlobalParams::findBase14FontFile(GooString *base14Name, GfxFont *font) {
@@ -1453,40 +1410,15 @@ GBool GlobalParams::getErrQuiet() {
 }
 
 CharCodeToUnicode *GlobalParams::getCIDToUnicode(GooString *collection) {
-  GooString *fileName;
   CharCodeToUnicode *ctu;
 
   lockGlobalParams;
   if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
-    if ((fileName = (GooString *)cidToUnicodes->lookup(collection)) &&
-	(ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
-      cidToUnicodeCache->add(ctu);
-    }
-  }
-  unlockGlobalParams;
-  return ctu;
-}
-
-CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GooString *fontName) {
-  lockGlobalParams;
-  GooHashIter *iter;
-  unicodeToUnicodes->startIter(&iter);
-  GooString *fileName = nullptr;
-  GooString *fontPattern;
-  void *val;
-  while (!fileName && unicodeToUnicodes->getNext(&iter, &fontPattern, &val)) {
-    if (strstr(fontName->getCString(), fontPattern->getCString())) {
-      unicodeToUnicodes->killIter(&iter);
-      fileName = (GooString*)val;
-    }
-  }
-  CharCodeToUnicode *ctu = nullptr;
-  if (fileName) {
-    ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName);
-    if (!ctu) {
-      ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName);
-      if (ctu)
-         unicodeToUnicodeCache->add(ctu);
+    const auto cidToUnicode = cidToUnicodes.find(collection->getCString());
+    if (cidToUnicode != cidToUnicodes.end()) {
+      if((ctu = CharCodeToUnicode::parseCIDToUnicode(cidToUnicode->second.c_str(), collection))) {
+        cidToUnicodeCache->add(ctu);
+      }
     }
   }
   unlockGlobalParams;
@@ -1523,20 +1455,13 @@ UnicodeMap *GlobalParams::getTextEncoding() {
 
 GooList *GlobalParams::getEncodingNames()
 {
-  GooList *result = new GooList;
-  GooHashIter *iter;
-  GooString *key;
-  void *val;
-  residentUnicodeMaps->startIter(&iter);
-  while (residentUnicodeMaps->getNext(&iter, &key, &val)) {
-    result->append(key);
+  auto* const result = new GooList;
+  for (const auto& unicodeMap : residentUnicodeMaps) {
+    result->append(new GooString(unicodeMap.first.c_str()));
   }
-  residentUnicodeMaps->killIter(&iter);
-  unicodeMaps->startIter(&iter);
-  while (unicodeMaps->getNext(&iter, &key, &val)) {
-    result->append(key);
+  for (const auto& unicodeMap : unicodeMaps) {
+    result->append(new GooString(unicodeMap.first.c_str()));
   }
-  unicodeMaps->killIter(&iter);
   return result;
 }
 
@@ -1546,7 +1471,7 @@ GooList *GlobalParams::getEncodingNames()
 
 void GlobalParams::addFontFile(GooString *fontName, GooString *path) {
   lockGlobalParams;
-  fontFiles->add(fontName, path);
+  fontFiles[fontName->getCString()] = path->getCString();
   unlockGlobalParams;
 }
 
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index e3d660cf..09a39814 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -44,6 +44,9 @@
 #include <stdio.h>
 #include "goo/gtypes.h"
 #include "CharTypes.h"
+#include "UnicodeMap.h"
+#include <unordered_map>
+#include <string>
 
 #ifdef MULTITHREADED
 #include "goo/GooMutex.h"
@@ -51,11 +54,9 @@
 
 class GooString;
 class GooList;
-class GooHash;
 class NameToCharCode;
 class CharCodeToUnicode;
 class CharCodeToUnicodeCache;
-class UnicodeMap;
 class UnicodeMapCache;
 class CMap;
 class CMapCache;
@@ -147,7 +148,7 @@ public:
   GBool getErrQuiet();
 
   CharCodeToUnicode *getCIDToUnicode(GooString *collection);
-  CharCodeToUnicode *getUnicodeToUnicode(GooString *fontName);
+  CharCodeToUnicode *getUnicodeToUnicode(GooString *) { return nullptr; }
   UnicodeMap *getUnicodeMap(GooString *encodingName);
   CMap *getCMap(GooString *collection, GooString *cMapName, Stream *stream = NULL);
   UnicodeMap *getTextEncoding();
@@ -199,24 +200,24 @@ private:
     nameToUnicodeZapfDingbats;
   NameToCharCode *		// mapping from char name to Unicode for text
     nameToUnicodeText;		// extraction
-  GooHash *cidToUnicodes;		// files for mappings from char collections
-				//   to Unicode, indexed by collection name
-				//   [GooString]
-  GooHash *unicodeToUnicodes;	// files for Unicode-to-Unicode mappings,
-				//   indexed by font name pattern [GooString]
-  GooHash *residentUnicodeMaps;	// mappings from Unicode to char codes,
-				//   indexed by encoding name [UnicodeMap]
-  GooHash *unicodeMaps;		// files for mappings from Unicode to char
-				//   codes, indexed by encoding name [GooString]
-  GooHash *cMapDirs;		// list of CMap dirs, indexed by collection
-				//   name [GooList[GooString]]
+  // files for mappings from char collections
+  // to Unicode, indexed by collection name
+  std::unordered_map<std::string, std::string> cidToUnicodes;
+  // mappings from Unicode to char codes,
+  // indexed by encoding name
+  std::unordered_map<std::string, UnicodeMap> residentUnicodeMaps;
+  // files for mappings from Unicode to char
+  // codes, indexed by encoding name
+  std::unordered_map<std::string, std::string> unicodeMaps;
+  // list of CMap dirs, indexed by collection
+  std::unordered_multimap<std::string, std::string> cMapDirs;
   GooList *toUnicodeDirs;		// list of ToUnicode CMap dirs [GooString]
   GBool baseFontsInitialized;
 #ifdef _WIN32
   GooHash *substFiles;	// windows font substitutes (for CID fonts)
 #endif
-  GooHash *fontFiles;		// font files: font name mapped to path
-				//   [GString]
+  // font files: font name mapped to path
+  std::unordered_map<std::string, std::string> fontFiles;
   SysFontList *sysFonts;	// system fonts
   GBool psExpandSmaller;	// expand smaller pages to fill paper
   GBool psShrinkLarger;		// shrink larger pages to fit paper
-- 
2.16.1


From e6f09bd2a008ea6e5a6858f1d2a0bc13db5e1536 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 18 Feb 2018 16:11:29 +0100
Subject: [PATCH 3/6] Replace GooHash by std::unordered_map in OutputDev.

---
 poppler/Gfx.cc         | 19 +++----------------
 poppler/OutputDev.cc   | 14 +++-----------
 poppler/OutputDev.h    | 14 ++++++++------
 poppler/ProfileData.cc |  9 ---------
 poppler/ProfileData.h  | 24 +++++++++---------------
 test/pdf-inspector.cc  | 16 ++++------------
 6 files changed, 27 insertions(+), 69 deletions(-)

diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 4f6c33f8..7683d532 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -59,7 +59,6 @@
 #include <memory>
 #include "goo/gmem.h"
 #include "goo/GooTimer.h"
-#include "goo/GooHash.h"
 #include "GlobalParams.h"
 #include "CharTypes.h"
 #include "Object.h"
@@ -739,21 +738,9 @@ void Gfx::go(GBool topLevel) {
 
       // Update the profile information
       if (unlikely(profileCommands)) {
-	GooHash *hash;
-
-	hash = out->getProfileHash ();
-	if (hash) {
-	  GooString *cmd_g;
-	  ProfileData *data_p;
-
-	  cmd_g = new GooString (obj.getCmd());
-	  data_p = (ProfileData *)hash->lookup (cmd_g);
-	  if (data_p == nullptr) {
-	    data_p = new ProfileData();
-	    hash->add (cmd_g, data_p);
-	  }
-	  
-	  data_p->addElement(timer->getElapsed ());
+    if (auto* const hash = out->getProfileHash ()) {
+      auto& data = (*hash)[obj.getCmd()];
+      data.addElement(timer->getElapsed());
 	}
 	delete timer;
       }
diff --git a/poppler/OutputDev.cc b/poppler/OutputDev.cc
index 8afa7052..fe09bd3d 100644
--- a/poppler/OutputDev.cc
+++ b/poppler/OutputDev.cc
@@ -36,7 +36,6 @@
 #include "Stream.h"
 #include "GfxState.h"
 #include "OutputDev.h"
-#include "goo/GooHash.h"
 
 //------------------------------------------------------------------------
 // OutputDev
@@ -179,18 +178,11 @@ void OutputDev::opiEnd(GfxState *state, Dict *opiDict) {
 #endif
 
 void OutputDev::startProfile() {
-  if (profileHash)
-    delete profileHash;
-
-  profileHash = new GooHash (true);
+  profileHash.reset(new std::unordered_map<std::string, ProfileData>);
 }
 
-GooHash *OutputDev::endProfile() {
-  GooHash *profile = profileHash;
-
-  profileHash = nullptr;
-
-  return profile;
+std::unique_ptr<std::unordered_map<std::string, ProfileData>> OutputDev::endProfile() {
+  return std::move(profileHash);
 }
 
 #ifdef USE_CMS
diff --git a/poppler/OutputDev.h b/poppler/OutputDev.h
index aca84cda..ed5910b4 100644
--- a/poppler/OutputDev.h
+++ b/poppler/OutputDev.h
@@ -42,10 +42,13 @@
 #include "CharTypes.h"
 #include "Object.h"
 #include "PopplerCache.h"
+#include <memory>
+#include <unordered_map>
+#include <string>
+#include "ProfileData.h"
 
 class Annot;
 class Dict;
-class GooHash;
 class GooString;
 class GfxState;
 class Gfx;
@@ -79,7 +82,6 @@ public:
  : iccColorSpaceCache(5)
 #endif
   {
-      profileHash = nullptr;
   }
 
   // Destructor.
@@ -327,9 +329,9 @@ public:
   virtual void psXObject(Stream * /*psStream*/, Stream * /*level1Stream*/) {}
 
   //----- Profiling
-  virtual void startProfile();
-  virtual GooHash *getProfileHash() {return profileHash; }
-  virtual GooHash *endProfile();
+  void startProfile();
+  std::unordered_map<std::string, ProfileData>* getProfileHash() const { return profileHash.get(); }
+  std::unique_ptr<std::unordered_map<std::string, ProfileData>> endProfile();
 
   //----- transparency groups and soft masks
   virtual GBool checkTransparencyGroup(GfxState * /*state*/, GBool /*knockout*/) { return gTrue; }
@@ -359,7 +361,7 @@ private:
 
   double defCTM[6];		// default coordinate transform matrix
   double defICTM[6];		// inverse of default CTM
-  GooHash *profileHash;
+  std::unique_ptr<std::unordered_map<std::string, ProfileData>> profileHash;
 
 #ifdef USE_CMS
   PopplerCache iccColorSpaceCache;
diff --git a/poppler/ProfileData.cc b/poppler/ProfileData.cc
index a0c44747..1044913c 100644
--- a/poppler/ProfileData.cc
+++ b/poppler/ProfileData.cc
@@ -12,21 +12,12 @@
 #pragma implementation
 #endif
 
-#include <stdlib.h>
-#include <stddef.h>
 #include "ProfileData.h"
 
 //------------------------------------------------------------------------
 // ProfileData
 //------------------------------------------------------------------------
 
-ProfileData::ProfileData() {
-	count = 0;
-	total = 0.0;
-	min = 0.0;
-	max = 0.0;
-}
-
 void
 ProfileData::addElement (double elapsed) {
 	if (count == 0) {
diff --git a/poppler/ProfileData.h b/poppler/ProfileData.h
index 418ee010..af52edea 100644
--- a/poppler/ProfileData.h
+++ b/poppler/ProfileData.h
@@ -19,23 +19,17 @@
 
 class ProfileData {
 public:
-
-  // Constructor.
-  ProfileData ();
-
-  // Destructor.
-  ~ProfileData() {}
-
   void addElement (double elapsed);
-  int getCount () { return count; }
-  double getTotal () { return total; }
-  double getMin () { return max; }
-  double getMax () { return max; }
+
+  int getCount () const { return count; }
+  double getTotal () const { return total; }
+  double getMin () const { return max; }
+  double getMax () const { return max; }
 private:
-  int count;			// size of <elems> array
-  double total;			// number of elements in array
-  double min;			// reference count
-  double max;			// reference count
+  int count = 0;		// size of <elems> array
+  double total = 0.0;   // number of elements in array
+  double min = 0.0;     // reference count
+  double max = 0.0; 	// reference count
 };
 
 #endif
diff --git a/test/pdf-inspector.cc b/test/pdf-inspector.cc
index d672add1..4815fdf3 100644
--- a/test/pdf-inspector.cc
+++ b/test/pdf-inspector.cc
@@ -13,7 +13,6 @@
 #endif
 
 #include <goo/gmem.h>
-#include <goo/GooHash.h>
 #include <goo/GooTimer.h>
 #include <splash/SplashTypes.h>
 #include <splash/SplashBitmap.h>
@@ -214,10 +213,6 @@ PdfInspector::on_analyze_clicked (GtkWidget *widget, PdfInspector *inspector)
 void
 PdfInspector::analyze_page (int page)
 {
-  GooHashIter *iter;
-  GooHash *hash;
-  GooString *key;
-  void *p;
   GtkWidget *label;
   char *text;
   cairo_t *cr;
@@ -245,24 +240,21 @@ PdfInspector::analyze_page (int page)
   g_free (text);
 
   // Individual times;
-  hash = output->endProfile ();
-  hash->startIter(&iter);
-  while (hash->getNext(&iter, &key, &p))
+  auto hash = output->endProfile ();
+  for (const auto& kvp : *hash)
     {
       GtkTreeIter tree_iter;
-      ProfileData *data_p = (ProfileData *) p;
+      const auto* const data_p = &kvp.second;
 
       gtk_list_store_append (GTK_LIST_STORE (model), &tree_iter);
       gtk_list_store_set (GTK_LIST_STORE (model), &tree_iter,
-			  OP_STRING, key->getCString(),
+              OP_STRING, kvp.first.c_str(),
 			  OP_COUNT, data_p->getCount (),
 			  OP_TOTAL, data_p->getTotal (),
 			  OP_MIN, data_p->getMin (),
 			  OP_MAX, data_p->getMax (),
 			  -1);
     }
-  hash->killIter(&iter);
-  deleteGooHash (hash, ProfileData);
 }
  
 void
-- 
2.16.1


From eaa7edd8c789d3323cf63757e325c4024119d378 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 18 Feb 2018 16:11:55 +0100
Subject: [PATCH 4/6] Replace GooHash by std::unordered_map in PSOutputDev.

---
 poppler/PSOutputDev.cc | 30 ++++++++++--------------------
 poppler/PSOutputDev.h  |  8 +++++---
 2 files changed, 15 insertions(+), 23 deletions(-)

diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 2f55557c..dad3695b 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -52,7 +52,6 @@
 #include <algorithm>
 #include "goo/GooString.h"
 #include "goo/GooList.h"
-#include "goo/GooHash.h"
 #include "poppler-config.h"
 #include "GlobalParams.h"
 #include "Object.h"
@@ -1107,8 +1106,6 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *doc,
   customCodeCbkData = customCodeCbkDataA;
 
   fontIDs = nullptr;
-  fontNames = new GooHash(gTrue);
-  fontMaxValidGlyph = new GooHash(gTrue);
   t1FontNames = nullptr;
   font8Info = nullptr;
   font16Enc = nullptr;
@@ -1176,8 +1173,6 @@ PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
   customCodeCbkData = customCodeCbkDataA;
 
   fontIDs = nullptr;
-  fontNames = new GooHash(gTrue);
-  fontMaxValidGlyph = new GooHash(gTrue);
   t1FontNames = nullptr;
   font8Info = nullptr;
   font16Enc = nullptr;
@@ -1408,7 +1403,7 @@ void PSOutputDev::postInit()
   fontIDLen = 0;
   fontIDs = (Ref *)gmallocn(fontIDSize, sizeof(Ref));
   for (i = 0; i < 14; ++i) {
-    fontNames->add(new GooString(psBase14SubstFonts[i].psName), 1);
+    fontNames.emplace(psBase14SubstFonts[i].psName);
   }
   t1FontNameSize = 64;
   t1FontNameLen = 0;
@@ -1498,8 +1493,6 @@ PSOutputDev::~PSOutputDev() {
   if (fontIDs) {
     gfree(fontIDs);
   }
-  delete fontNames;
-  delete fontMaxValidGlyph;
   if (t1FontNames) {
     for (i = 0; i < t1FontNameLen; ++i) {
       delete t1FontNames[i].psName;
@@ -2128,10 +2121,9 @@ void PSOutputDev::setupEmbeddedType1Font(Ref *id, GooString *psName) {
   GBool writePadding = gTrue;
 
   // check if font is already embedded
-  if (fontNames->lookupInt(psName)) {
+  if (!fontNames.emplace(psName->getCString()).second) {
     return;
   }
-  fontNames->add(psName->copy(), 1);
 
   // get the font stream and info
   Object obj1, obj2, obj3;
@@ -2307,10 +2299,9 @@ void PSOutputDev::setupExternalType1Font(GooString *fileName, GooString *psName)
   FILE *fontFile;
   int c;
 
-  if (fontNames->lookupInt(psName)) {
+  if (!fontNames.emplace(psName->getCString()).second) {
     return;
   }
-  fontNames->add(psName->copy(), 1);
 
   // beginning comment
   writePSFmt("%%BeginResource: font {0:t}\n", psName);
@@ -2546,8 +2537,9 @@ void PSOutputDev::setupExternalTrueTypeFont(GfxFont *font, GooString *fileName,
 
 void PSOutputDev::updateFontMaxValidGlyph(GfxFont *font, int maxValidGlyph) {
   if (maxValidGlyph >= 0 && font->getName()) {
-    if (maxValidGlyph > fontMaxValidGlyph->lookupInt(font->getName())) {
-      fontMaxValidGlyph->replace(font->getName()->copy(), maxValidGlyph);
+    auto& fontMaxValidGlyph = this->fontMaxValidGlyph[font->getName()->getCString()];
+    if (fontMaxValidGlyph < maxValidGlyph) {
+      fontMaxValidGlyph = maxValidGlyph;
     }
   }
 }
@@ -2871,16 +2863,14 @@ GooString *PSOutputDev::makePSFontName(GfxFont *font, Ref *id) {
 
   if ((s = font->getEmbeddedFontName())) {
     psName = filterPSName(s);
-    if (!fontNames->lookupInt(psName)) {
-      fontNames->add(psName->copy(), 1);
+    if (fontNames.emplace(psName->getCString()).second) {
       return psName;
     }
     delete psName;
   }
   if ((s = font->getName())) {
     psName = filterPSName(s);
-    if (!fontNames->lookupInt(psName)) {
-      fontNames->add(psName->copy(), 1);
+    if (fontNames.emplace(psName->getCString()).second) {
       return psName;
     }
     delete psName;
@@ -2895,7 +2885,7 @@ GooString *PSOutputDev::makePSFontName(GfxFont *font, Ref *id) {
     psName->append('_')->append(s);
     delete s;
   }
-  fontNames->add(psName->copy(), 1);
+  fontNames.emplace(psName->getCString());
   return psName;
 }
 
@@ -5041,7 +5031,7 @@ void PSOutputDev::drawString(GfxState *state, GooString *s) {
   if (!(font = state->getFont())) {
     return;
   }
-  maxGlyphInt = (font->getName()? fontMaxValidGlyph->lookupInt(font->getName()): 0);
+  maxGlyphInt = (font->getName() ? fontMaxValidGlyph[font->getName()->getCString()] : 0);
   if (maxGlyphInt < 0) maxGlyphInt = 0;
   maxGlyph = (CharCode) maxGlyphInt;
   wMode = font->getWMode();
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index 330b81b3..98ac9c98 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -46,8 +46,10 @@
 #include <set>
 #include <map>
 #include <vector>
+#include <unordered_set>
+#include <unordered_map>
+#include <string>
 
-class GHooash;
 class PDFDoc;
 class XRef;
 class Function;
@@ -474,8 +476,8 @@ private:
   int fontIDLen;		// number of entries in fontIDs array
   int fontIDSize;		// size of fontIDs array
   std::set<int> resourceIDs;	// list of object IDs of objects containing Resources we've already set up
-  GooHash *fontNames;		// all used font names
-  GooHash *fontMaxValidGlyph;	// max valid glyph of each font
+  std::unordered_set<std::string> fontNames; // all used font names
+  std::unordered_map<std::string, int> fontMaxValidGlyph; // max valid glyph of each font
   PST1FontName *t1FontNames;	// font names for Type 1/1C fonts
   int t1FontNameLen;		// number of entries in t1FontNames array
   int t1FontNameSize;		// size of t1FontNames array
-- 
2.16.1


From 64f5d4cca814683f1bd8b98559d549c3a4a26b5e Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 18 Feb 2018 16:12:19 +0100
Subject: [PATCH 5/6] Remove GooHash after replacing it by std::unordered_map.

---
 CMakeLists.txt |   2 -
 goo/GooHash.cc | 402 ---------------------------------------------------------
 goo/GooHash.h  |  92 -------------
 3 files changed, 496 deletions(-)
 delete mode 100644 goo/GooHash.cc
 delete mode 100644 goo/GooHash.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5e3d6a17..5156874b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -308,7 +308,6 @@ configure_file(poppler/poppler-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/popple
 set(poppler_SRCS
   goo/gfile.cc
   goo/gmempp.cc
-  goo/GooHash.cc
   goo/GooList.cc
   goo/GooTimer.cc
   goo/GooString.cc
@@ -572,7 +571,6 @@ if(ENABLE_XPDF_HEADERS)
     ${CMAKE_CURRENT_BINARY_DIR}/poppler/poppler-config.h
     DESTINATION include/poppler)
   install(FILES
-    goo/GooHash.h
     goo/GooList.h
     goo/GooTimer.h
     goo/GooMutex.h
diff --git a/goo/GooHash.cc b/goo/GooHash.cc
deleted file mode 100644
index cd39a5ae..00000000
--- a/goo/GooHash.cc
+++ /dev/null
@@ -1,402 +0,0 @@
-//========================================================================
-//
-// GooHash.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) 2017 Albert Astals Cid <[email protected]>
-//
-// 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 "gmem.h"
-#include "GooString.h"
-#include "GooHash.h"
-#include "GooLikely.h"
-
-//------------------------------------------------------------------------
-
-struct GooHashBucket {
-  GooString *key;
-  union {
-    void *p;
-    int i;
-  } val;
-  GooHashBucket *next;
-};
-
-struct GooHashIter {
-  int h;
-  GooHashBucket *p;
-};
-
-//------------------------------------------------------------------------
-
-GooHash::GooHash(GBool deleteKeysA) {
-  int h;
-
-  deleteKeys = deleteKeysA;
-  size = 7;
-  tab = (GooHashBucket **)gmallocn(size, sizeof(GooHashBucket *));
-  for (h = 0; h < size; ++h) {
-    tab[h] = nullptr;
-  }
-  len = 0;
-}
-
-GooHash::~GooHash() {
-  GooHashBucket *p;
-  int h;
-
-  for (h = 0; h < size; ++h) {
-    while (tab[h]) {
-      p = tab[h];
-      tab[h] = p->next;
-      if (deleteKeys) {
-	delete p->key;
-      }
-      delete p;
-    }
-  }
-  gfree(tab);
-}
-
-void GooHash::add(GooString *key, void *val) {
-  GooHashBucket *p;
-  int h;
-
-  // expand the table if necessary
-  if (len >= size) {
-    expand();
-  }
-
-  // add the new symbol
-  p = new GooHashBucket;
-  p->key = key;
-  p->val.p = val;
-  h = hash(key);
-  p->next = tab[h];
-  tab[h] = p;
-  ++len;
-}
-
-void GooHash::add(GooString *key, int val) {
-  GooHashBucket *p;
-  int h;
-
-  // expand the table if necessary
-  if (len >= size) {
-    expand();
-  }
-
-  // add the new symbol
-  p = new GooHashBucket;
-  p->key = key;
-  p->val.i = val;
-  h = hash(key);
-  p->next = tab[h];
-  tab[h] = p;
-  ++len;
-}
-
-void GooHash::replace(GooString *key, void *val) {
-  GooHashBucket *p;
-  int h;
-
-  if ((p = find(key, &h))) {
-    p->val.p = val;
-    if (deleteKeys) {
-      delete key;
-    }
-  } else {
-    add(key, val);
-  }
-}
-
-void GooHash::replace(GooString *key, int val) {
-  GooHashBucket *p;
-  int h;
-
-  if ((p = find(key, &h))) {
-    p->val.i = val;
-    if (deleteKeys) {
-      delete key;
-    }
-  } else {
-    add(key, val);
-  }
-}
-
-void *GooHash::lookup(GooString *key) {
-  GooHashBucket *p;
-  int h;
-
-  if (!(p = find(key, &h))) {
-    return nullptr;
-  }
-  return p->val.p;
-}
-
-int GooHash::lookupInt(GooString *key) {
-  GooHashBucket *p;
-  int h;
-
-  if (!(p = find(key, &h))) {
-    return 0;
-  }
-  return p->val.i;
-}
-
-void *GooHash::lookup(const char *key) {
-  GooHashBucket *p;
-  int h;
-
-  if (!(p = find(key, &h))) {
-    return nullptr;
-  }
-  return p->val.p;
-}
-
-int GooHash::lookupInt(const char *key) {
-  GooHashBucket *p;
-  int h;
-
-  if (!(p = find(key, &h))) {
-    return 0;
-  }
-  return p->val.i;
-}
-
-void *GooHash::remove(GooString *key) {
-  GooHashBucket *p;
-  GooHashBucket **q;
-  void *val;
-  int h;
-
-  if (!(p = find(key, &h))) {
-    return nullptr;
-  }
-  q = &tab[h];
-  while (*q != p) {
-    q = &((*q)->next);
-  }
-  *q = p->next;
-  if (deleteKeys) {
-    delete p->key;
-  }
-  val = p->val.p;
-  delete p;
-  --len;
-  return val;
-}
-
-int GooHash::removeInt(GooString *key) {
-  GooHashBucket *p;
-  GooHashBucket **q;
-  int val;
-  int h;
-
-  if (!(p = find(key, &h))) {
-    return 0;
-  }
-  q = &tab[h];
-  while (*q != p) {
-    q = &((*q)->next);
-  }
-  *q = p->next;
-  if (deleteKeys) {
-    delete p->key;
-  }
-  val = p->val.i;
-  delete p;
-  --len;
-  return val;
-}
-
-void *GooHash::remove(const char *key) {
-  GooHashBucket *p;
-  GooHashBucket **q;
-  void *val;
-  int h;
-
-  if (!(p = find(key, &h))) {
-    return nullptr;
-  }
-  q = &tab[h];
-  while (*q != p) {
-    q = &((*q)->next);
-  }
-  *q = p->next;
-  if (deleteKeys) {
-    delete p->key;
-  }
-  val = p->val.p;
-  delete p;
-  --len;
-  return val;
-}
-
-int GooHash::removeInt(const char *key) {
-  GooHashBucket *p;
-  GooHashBucket **q;
-  int val;
-  int h;
-
-  if (!(p = find(key, &h))) {
-    return 0;
-  }
-  q = &tab[h];
-  while (*q != p) {
-    q = &((*q)->next);
-  }
-  *q = p->next;
-  if (deleteKeys) {
-    delete p->key;
-  }
-  val = p->val.i;
-  delete p;
-  --len;
-  return val;
-}
-
-void GooHash::startIter(GooHashIter **iter) {
-  *iter = new GooHashIter;
-  (*iter)->h = -1;
-  (*iter)->p = nullptr;
-}
-
-GBool GooHash::getNext(GooHashIter **iter, GooString **key, void **val) {
-  if (!*iter) {
-    return gFalse;
-  }
-  if ((*iter)->p) {
-    (*iter)->p = (*iter)->p->next;
-  }
-  while (!(*iter)->p) {
-    if (++(*iter)->h == size) {
-      delete *iter;
-      *iter = nullptr;
-      return gFalse;
-    }
-    (*iter)->p = tab[(*iter)->h];
-  }
-  *key = (*iter)->p->key;
-  *val = (*iter)->p->val.p;
-  return gTrue;
-}
-
-GBool GooHash::getNext(GooHashIter **iter, GooString **key, int *val) {
-  if (!*iter) {
-    return gFalse;
-  }
-  if ((*iter)->p) {
-    (*iter)->p = (*iter)->p->next;
-  }
-  while (!(*iter)->p) {
-    if (++(*iter)->h == size) {
-      delete *iter;
-      *iter = nullptr;
-      return gFalse;
-    }
-    (*iter)->p = tab[(*iter)->h];
-  }
-  *key = (*iter)->p->key;
-  *val = (*iter)->p->val.i;
-  return gTrue;
-}
-
-void GooHash::killIter(GooHashIter **iter) {
-  delete *iter;
-  *iter = nullptr;
-}
-
-void GooHash::expand() {
-  GooHashBucket **oldTab;
-  GooHashBucket *p;
-  int oldSize, h, i;
-
-  oldSize = size;
-  oldTab = tab;
-  size = 2*size + 1;
-  tab = (GooHashBucket **)gmallocn(size, sizeof(GooHashBucket *));
-  for (h = 0; h < size; ++h) {
-    tab[h] = nullptr;
-  }
-  for (i = 0; i < oldSize; ++i) {
-    while (oldTab[i]) {
-      p = oldTab[i];
-      oldTab[i] = oldTab[i]->next;
-      h = hash(p->key);
-      p->next = tab[h];
-      tab[h] = p;
-    }
-  }
-  gfree(oldTab);
-}
-
-GooHashBucket *GooHash::find(GooString *key, int *h) {
-  GooHashBucket *p;
-
-  if (unlikely(!key))
-    return nullptr;
-
-  *h = hash(key);
-  for (p = tab[*h]; p; p = p->next) {
-    if (!p->key->cmp(key)) {
-      return p;
-    }
-  }
-  return nullptr;
-}
-
-GooHashBucket *GooHash::find(const char *key, int *h) {
-  GooHashBucket *p;
-
-  *h = hash(key);
-  for (p = tab[*h]; p; p = p->next) {
-    if (!p->key->cmp(key)) {
-      return p;
-    }
-  }
-  return nullptr;
-}
-
-int GooHash::hash(GooString *key) {
-  const char *p;
-  unsigned int h;
-  int i;
-
-  h = 0;
-  for (p = key->getCString(), i = 0; i < key->getLength(); ++p, ++i) {
-    h = 17 * h + (int)(*p & 0xff);
-  }
-  return (int)(h % size);
-}
-
-int GooHash::hash(const char *key) {
-  const char *p;
-  unsigned int h;
-
-  h = 0;
-  for (p = key; *p; ++p) {
-    h = 17 * h + (int)(*p & 0xff);
-  }
-  return (int)(h % size);
-}
diff --git a/goo/GooHash.h b/goo/GooHash.h
deleted file mode 100644
index eda19e31..00000000
--- a/goo/GooHash.h
+++ /dev/null
@@ -1,92 +0,0 @@
-//========================================================================
-//
-// GooHash.h
-//
-// 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) 2012 Albert Astals Cid <[email protected]>
-//
-// 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
-//
-//========================================================================
-
-#ifndef GHASH_H
-#define GHASH_H
-
-#ifdef USE_GCC_PRAGMAS
-#pragma interface
-#endif
-
-#include "gtypes.h"
-
-class GooString;
-struct GooHashBucket;
-struct GooHashIter;
-
-//------------------------------------------------------------------------
-
-class GooHash {
-public:
-
-  GooHash(GBool deleteKeysA = gFalse);
-  ~GooHash();
-  void add(GooString *key, void *val);
-  void add(GooString *key, int val);
-  void replace(GooString *key, void *val);
-  void replace(GooString *key, int val);
-  void *lookup(GooString *key);
-  int lookupInt(GooString *key);
-  void *lookup(const char *key);
-  int lookupInt(const char *key);
-  void *remove(GooString *key);
-  int removeInt(GooString *key);
-  void *remove(const char *key);
-  int removeInt(const char *key);
-  int getLength() { return len; }
-  void startIter(GooHashIter **iter);
-  GBool getNext(GooHashIter **iter, GooString **key, void **val);
-  GBool getNext(GooHashIter **iter, GooString **key, int *val);
-  void killIter(GooHashIter **iter);
-
-private:
-  GooHash(const GooHash &other);
-  GooHash& operator=(const GooHash &other);
-
-  void expand();
-  GooHashBucket *find(GooString *key, int *h);
-  GooHashBucket *find(const char *key, int *h);
-  int hash(GooString *key);
-  int hash(const char *key);
-
-  GBool deleteKeys;		// set if key strings should be deleted
-  int size;			// number of buckets
-  int len;			// number of entries
-  GooHashBucket **tab;
-};
-
-#define deleteGooHash(hash, T)                       \
-  do {                                             \
-    GooHash *_hash = (hash);                         \
-    {                                              \
-      GooHashIter *_iter;                            \
-      GooString *_key;                               \
-      void *_p;                                    \
-      _hash->startIter(&_iter);                    \
-      while (_hash->getNext(&_iter, &_key, &_p)) { \
-        delete (T*)_p;                             \
-      }                                            \
-      delete _hash;                                \
-    }                                              \
-  } while(0)
-
-#endif
-- 
2.16.1


From ef9eed8942d398ed3e41e248eecdf2b579abfae2 Mon Sep 17 00:00:00 2001
From: Adam Reichold <[email protected]>
Date: Sun, 18 Feb 2018 16:23:36 +0100
Subject: [PATCH 6/6] Also replace the Win32-specific usage of GooHash by
 std::unordered_map on a best-effort basis.

---
 poppler/GlobalParams.cc    |  6 ------
 poppler/GlobalParams.h     |  3 ++-
 poppler/GlobalParamsWin.cc | 23 +++++++++++------------
 3 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index a2def055..5b47e67d 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -564,9 +564,6 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir)
     }
   }
 
-#ifdef _WIN32
-  substFiles = new GooHash(gTrue);
-#endif
   nameToUnicodeZapfDingbats = new NameToCharCode();
   nameToUnicodeText = new NameToCharCode();
   toUnicodeDirs = new GooList();
@@ -746,9 +743,6 @@ GlobalParams::~GlobalParams() {
   delete nameToUnicodeZapfDingbats;
   delete nameToUnicodeText;
   deleteGooList(toUnicodeDirs, GooString);
-#ifdef _WIN32
-  deleteGooHash(substFiles, GooString);
-#endif
   delete sysFonts;
   delete textEncoding;
 
diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h
index 09a39814..69435bfc 100644
--- a/poppler/GlobalParams.h
+++ b/poppler/GlobalParams.h
@@ -214,7 +214,8 @@ private:
   GooList *toUnicodeDirs;		// list of ToUnicode CMap dirs [GooString]
   GBool baseFontsInitialized;
 #ifdef _WIN32
-  GooHash *substFiles;	// windows font substitutes (for CID fonts)
+  // windows font substitutes (for CID fonts)
+  std::unordered_map<std::string, std::string> substFiles;
 #endif
   // font files: font name mapped to path
   std::unordered_map<std::string, std::string> fontFiles;
diff --git a/poppler/GlobalParamsWin.cc b/poppler/GlobalParamsWin.cc
index 1734f6eb..725709e9 100644
--- a/poppler/GlobalParamsWin.cc
+++ b/poppler/GlobalParamsWin.cc
@@ -37,7 +37,6 @@ description for all fonts available in Windows. That's how MuPDF works.
 #include "goo/gmem.h"
 #include "goo/GooString.h"
 #include "goo/GooList.h"
-#include "goo/GooHash.h"
 #include "goo/gfile.h"
 #include "Error.h"
 #include "NameToCharCode.h"
@@ -479,7 +478,7 @@ void GlobalParams::setupBaseFonts(char * dir)
 	          addFontFile(new GooString(obj1.getName()), obj3.getString()->copy());
 	      // Aliases
 	      } else if (obj2.isName()) {
-	        substFiles->add(new GooString(obj1.getName()), new GooString(obj2.getName()));
+                substFiles.emplace(obj1.getName(), obj2.getName());
 	      }
 	    }
 	    obj1 = parser->getObj();
@@ -496,8 +495,8 @@ void GlobalParams::setupBaseFonts(char * dir)
     }
 }
 
-static const char *findSubstituteName(GfxFont *font, GooHash *fontFiles,
-                                      GooHash *substFiles,
+static const char *findSubstituteName(GfxFont *font, const std::unordered_map<std::string, std::string>& fontFiles,
+                                      const std::unordered_map<std::string, std::string>& substFiles,
                                       const char *origName)
 {
     assert(origName);
@@ -514,10 +513,10 @@ static const char *findSubstituteName(GfxFont *font, GooHash *fontFiles,
       name2->del(n - 11, 11);
       n -= 11;
     }
-    GooString *substName = (GooString *)substFiles->lookup(name2);
-    if (substName != nullptr) {
+    const auto substFile = substFiles.find(name2->getCString());
+    if (substFile != substFiles.end()) {
       delete name2;
-      return substName->getCString();
+      return substFile->second.c_str();
     }
 
     /* TODO: try to at least guess bold/italic/bolditalic from the name */
@@ -537,10 +536,10 @@ static const char *findSubstituteName(GfxFont *font, GooHash *fontFiles,
       else if ( !collection->cmp("Adobe-Korea1") )
         name3 = DEFAULT_CID_FONT_AK1_MSWIN;
 
-      if (name3 && fontFiles->lookup(name3))
+      if (name3 && fontFiles.count(name3) != 0)
         return name3;
 
-      if (fontFiles->lookup(DEFAULT_CID_FONT_MSWIN))
+      if (fontFiles.count(DEFAULT_CID_FONT_MSWIN) != 0)
         return DEFAULT_CID_FONT_MSWIN;
     } 
     return DEFAULT_SUBSTITUTE_FONT;
@@ -572,10 +571,10 @@ GooString *GlobalParams::findSystemFontFile(GfxFont *font,
     GooString *substFontName = new GooString(findSubstituteName(font, fontFiles,
                                                                 substFiles,
                                                                 fontName->getCString()));
-    GooString *path2 = nullptr;
     error(errSyntaxError, -1, "Couldn't find a font for '{0:t}', subst is '{1:t}'", fontName, substFontName);
-    if ((path2 = (GooString *)fontFiles->lookup(substFontName))) {
-      path = new GooString(path2);
+    const auto fontFile = fontFiles.find(substFontName);
+    if (fontFile != fontFiles.end()) {
+      path = new GooString(fontFile->second.c_str());
       if (substituteFontName)
 	substituteFontName->Set(path->getCString());
       if (!strcasecmp(path->getCString() + path->getLength() - 4, ".ttc")) {
-- 
2.16.1

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
poppler mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to