poppler/FontInfo.cc |   15 +++++----------
 poppler/FontInfo.h  |    6 ++++--
 2 files changed, 9 insertions(+), 12 deletions(-)

New commits:
commit 0ec33438f4a407c122c9bfc4dc34758203b50e8a
Author: Adam Reichold <[email protected]>
Date:   Sun Apr 7 20:48:30 2019 +0200

    Avoid duplicate set look-up and ordering overhead when tracking visited 
fonts and objects in FontScanner.

diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index b7e970d7..e6ccfb26 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -115,9 +115,8 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, 
std::vector<FontInfo
         Ref fontRef = *font->getID();
 
         // add this font to the list if not already found
-        if (fonts.find(fontRef.num) == fonts.end()) {
+       if (fonts.insert(fontRef.num).second) {
          fontsList->push_back(new FontInfo(font, xrefA));
-          fonts.insert(fontRef.num);
         }
       }
     }
@@ -135,11 +134,9 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict 
*resDict, std::vector<FontInfo
         const Object obj2 = objDict.getDict()->getVal(i, &obj2Ref);
         if (obj2Ref != Ref::INVALID()) {
           // check for an already-seen object
-          if (visitedObjects.find(obj2Ref.num) != visitedObjects.end()) {
+         if (!visitedObjects.insert(obj2Ref.num).second) {
             continue;
-          }
-
-          visitedObjects.insert(obj2Ref.num);
+         }
         }
 
         if (obj2.isStream()) {
@@ -147,11 +144,9 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict 
*resDict, std::vector<FontInfo
           const Object resObj = obj2.streamGetDict()->lookup("Resources", 
&resourcesRef);
 
           if (resourcesRef != Ref::INVALID()) {
-            if (visitedObjects.find(resourcesRef.num) != visitedObjects.end()) 
{
+           if (!visitedObjects.insert(resourcesRef.num).second) {
               continue;
-            }
-
-            visitedObjects.insert(resourcesRef.num);
+           }
           }
 
           if (resObj.isDict() && resObj.getDict() != resDict) {
diff --git a/poppler/FontInfo.h b/poppler/FontInfo.h
index 6394c4ac..2a40bcda 100644
--- a/poppler/FontInfo.h
+++ b/poppler/FontInfo.h
@@ -28,6 +28,8 @@
 
 #include "Object.h"
 
+#include <unordered_set>
+
 class GfxFont;
 class PDFDoc;
 
@@ -95,8 +97,8 @@ private:
 
   PDFDoc *doc;
   int currentPage;
-  std::set<int> fonts;
-  std::set<int> visitedObjects;
+  std::unordered_set<int> fonts;
+  std::unordered_set<int> visitedObjects;
 
   void scanFonts(XRef *xrefA, Dict *resDict, std::vector<FontInfo*> 
*fontsList);
 };
_______________________________________________
poppler mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to