[poppler] poppler/Gfx.cc poppler/Gfx.h

Albert Astals Cid aacid at kemper.freedesktop.org
Mon Aug 11 15:40:14 PDT 2008


 poppler/Gfx.cc |   14 ++++++++++++--
 poppler/Gfx.h  |    3 +++
 2 files changed, 15 insertions(+), 2 deletions(-)

New commits:
commit 123a87aff2e35b10efe6a1d715585b427e4a9afa
Author: Albert Astals Cid <tsdgeos at samsung.localdomain>
Date:   Tue Aug 12 00:37:09 2008 +0200

    Cache the last created GfxResource, very useful because some pdf created by pstopdf push and pop the same GfxResource all the time
    
    This brings us a speedup of 16 times (from 11 seconds to about 600 msec) in kde bug 168663

diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 41ccdb7..e1cd847 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -465,6 +465,7 @@ Gfx::Gfx(XRef *xrefA, OutputDev *outA, int pageNum, Dict *resDict, Catalog *cata
 	 void *abortCheckCbkDataA) {
   int i;
 
+  lastResource = NULL;
   xref = xrefA;
   catalog = catalogA;
   subPage = gFalse;
@@ -509,6 +510,7 @@ Gfx::Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict, Catalog *catalogA,
 	 void *abortCheckCbkDataA) {
   int i;
 
+  lastResource = NULL;
   xref = xrefA;
   catalog = catalogA;
   subPage = gTrue;
@@ -556,6 +558,7 @@ Gfx::~Gfx() {
   if (state) {
     delete state;
   }
+  delete lastResource;
 }
 
 void Gfx::display(Object *obj, GBool topLevel) {
@@ -4379,13 +4382,20 @@ void Gfx::restoreState() {
 }
 
 void Gfx::pushResources(Dict *resDict) {
-  res = new GfxResources(xref, resDict, res);
+  if (lastResource && resDict == lastResourceDict) res = lastResource;
+  else
+  {
+    delete lastResource;
+    res = new GfxResources(xref, resDict, res);
+    lastResource = res;
+    lastResourceDict = resDict;
+  }
 }
 
 void Gfx::popResources() {
   GfxResources *resPtr;
 
   resPtr = res->getNext();
-  delete res;
+  if (resPtr == NULL) delete res;
   res = resPtr;
 }
diff --git a/poppler/Gfx.h b/poppler/Gfx.h
index 10be638..c56558f 100644
--- a/poppler/Gfx.h
+++ b/poppler/Gfx.h
@@ -173,6 +173,9 @@ private:
     (*abortCheckCbk)(void *data);
   void *abortCheckCbkData;
 
+  GfxResources *lastResource;	// last used GfxResource
+  Dict *lastResourceDict;	// last used GfxResource Dict
+
   static Operator opTab[];	// table of operators
 
   void go(GBool topLevel);


More information about the poppler mailing list