[poppler] 3 commits - poppler/SplashOutputDev.cc poppler/SplashOutputDev.h splash/Splash.cc splash/SplashPath.cc splash/SplashPath.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Aug 31 15:28:10 UTC 2018


 poppler/SplashOutputDev.cc |   69 +++++++++++++++------------------------------
 poppler/SplashOutputDev.h  |    2 -
 splash/Splash.cc           |   36 ++++++++---------------
 splash/SplashPath.cc       |   17 +++++++++++
 splash/SplashPath.h        |    1 
 5 files changed, 56 insertions(+), 69 deletions(-)

New commits:
commit 51f1c813970627db0b8804f6a729eed79ac9dfb4
Author: Stefan Brüns <stefan.bruens at rwth-aachen.de>
Date:   Fri Aug 31 00:27:13 2018 +0200

    SplashPath: Allocate temporary pathes on the stack
    
    The majority of SplashPath'es are created using
    convertPath(GfxState *, GfxPath *), and are only temporary,
    i.e. with function scope.
    
    Returning a SplashPath instead of a pointer from convertPath()
    - which is cheap due to the move constructor - saves recurrent
    new/delete's for each stroke/fill/... operation.

diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index 3e883970..a8e31fff 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -2294,88 +2294,71 @@ reload:
 }
 
 void SplashOutputDev::stroke(GfxState *state) {
-  SplashPath *path;
-
   if (state->getStrokeColorSpace()->isNonMarking()) {
     return;
   }
   setOverprintMask(state->getStrokeColorSpace(), state->getStrokeOverprint(),
 		   state->getOverprintMode(), state->getStrokeColor());
-  path = convertPath(state, state->getPath(), gFalse);
-  splash->stroke(path);
-  delete path;
+  SplashPath path = convertPath(state, state->getPath(), gFalse);
+  splash->stroke(&path);
 }
 
 void SplashOutputDev::fill(GfxState *state) {
-  SplashPath *path;
-
   if (state->getFillColorSpace()->isNonMarking()) {
     return;
   }
   setOverprintMask(state->getFillColorSpace(), state->getFillOverprint(),
 		   state->getOverprintMode(), state->getFillColor());
-  path = convertPath(state, state->getPath(), gTrue);
-  splash->fill(path, gFalse);
-  delete path;
+  SplashPath path = convertPath(state, state->getPath(), gTrue);
+  splash->fill(&path, gFalse);
 }
 
 void SplashOutputDev::eoFill(GfxState *state) {
-  SplashPath *path;
-
   if (state->getFillColorSpace()->isNonMarking()) {
     return;
   }
   setOverprintMask(state->getFillColorSpace(), state->getFillOverprint(),
 		   state->getOverprintMode(), state->getFillColor());
-  path = convertPath(state, state->getPath(), gTrue);
-  splash->fill(path, gTrue);
-  delete path;
+  SplashPath path = convertPath(state, state->getPath(), gTrue);
+  splash->fill(&path, gTrue);
 }
 
 void SplashOutputDev::clip(GfxState *state) {
-  SplashPath *path;
-
-  path = convertPath(state, state->getPath(), gTrue);
-  splash->clipToPath(path, gFalse);
-  delete path;
+  SplashPath path = convertPath(state, state->getPath(), gTrue);
+  splash->clipToPath(&path, gFalse);
 }
 
 void SplashOutputDev::eoClip(GfxState *state) {
-  SplashPath *path;
-
-  path = convertPath(state, state->getPath(), gTrue);
-  splash->clipToPath(path, gTrue);
-  delete path;
+  SplashPath path = convertPath(state, state->getPath(), gTrue);
+  splash->clipToPath(&path, gTrue);
 }
 
 void SplashOutputDev::clipToStrokePath(GfxState *state) {
-  SplashPath *path, *path2;
+  SplashPath *path2;
 
-  path = convertPath(state, state->getPath(), gFalse);
-  path2 = splash->makeStrokePath(path, state->getLineWidth());
-  delete path;
+  SplashPath path = convertPath(state, state->getPath(), gFalse);
+  path2 = splash->makeStrokePath(&path, state->getLineWidth());
   splash->clipToPath(path2, gFalse);
   delete path2;
 }
 
-SplashPath *SplashOutputDev::convertPath(GfxState *state, GfxPath *path,
+SplashPath SplashOutputDev::convertPath(GfxState *state, GfxPath *path,
 					 GBool dropEmptySubpaths) {
-  SplashPath *sPath;
+  SplashPath sPath;
   GfxSubpath *subpath;
   int n, i, j;
 
   n = dropEmptySubpaths ? 1 : 0;
-  sPath = new SplashPath();
   for (i = 0; i < path->getNumSubpaths(); ++i) {
     subpath = path->getSubpath(i);
     if (subpath->getNumPoints() > n) {
-      sPath->reserve(subpath->getNumPoints() + 1);
-      sPath->moveTo((SplashCoord)subpath->getX(0),
+      sPath.reserve(subpath->getNumPoints() + 1);
+      sPath.moveTo((SplashCoord)subpath->getX(0),
 		    (SplashCoord)subpath->getY(0));
       j = 1;
       while (j < subpath->getNumPoints()) {
 	if (subpath->getCurve(j)) {
-	  sPath->curveTo((SplashCoord)subpath->getX(j),
+	  sPath.curveTo((SplashCoord)subpath->getX(j),
 			 (SplashCoord)subpath->getY(j),
 			 (SplashCoord)subpath->getX(j+1),
 			 (SplashCoord)subpath->getY(j+1),
@@ -2383,13 +2366,13 @@ SplashPath *SplashOutputDev::convertPath(GfxState *state, GfxPath *path,
 			 (SplashCoord)subpath->getY(j+2));
 	  j += 3;
 	} else {
-	  sPath->lineTo((SplashCoord)subpath->getX(j),
+	  sPath.lineTo((SplashCoord)subpath->getX(j),
 			(SplashCoord)subpath->getY(j));
 	  ++j;
 	}
       }
       if (subpath->isClosed()) {
-	sPath->close();
+	sPath.close();
       }
     }
   }
@@ -4784,7 +4767,6 @@ GBool SplashOutputDev::gouraudTriangleShadedFill(GfxState *state, GfxGouraudTria
 
 GBool SplashOutputDev::univariateShadedFill(GfxState *state, SplashUnivariatePattern *pattern, double tMin, double tMax) {
   double xMin, yMin, xMax, yMax;
-  SplashPath *path;
   GBool vaa = getVectorAntialias();
   // restore vector antialias because we support it here
   setVectorAntialias(gTrue);
@@ -4831,17 +4813,16 @@ GBool SplashOutputDev::univariateShadedFill(GfxState *state, SplashUnivariatePat
   state->lineTo(xMax, yMax);
   state->lineTo(xMin, yMax);
   state->closePath();
-  path = convertPath(state, state->getPath(), gTrue);
+  SplashPath path = convertPath(state, state->getPath(), gTrue);
 
 #ifdef SPLASH_CMYK
   pattern->getShading()->getColorSpace()->createMapping(bitmap->getSeparationList(), SPOT_NCOMPS);
 #endif
   setOverprintMask(pattern->getShading()->getColorSpace(), state->getFillOverprint(),
 		   state->getOverprintMode(), nullptr);
-  retVal = (splash->shadedFill(path, pattern->getShading()->getHasBBox(), pattern) == splashOk);
+  retVal = (splash->shadedFill(&path, pattern->getShading()->getHasBBox(), pattern) == splashOk);
   state->clearPath();
   setVectorAntialias(vaa);
-  delete path;
 
   return retVal;
 }
@@ -4849,7 +4830,6 @@ GBool SplashOutputDev::univariateShadedFill(GfxState *state, SplashUnivariatePat
 GBool SplashOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading) {
   SplashFunctionPattern *pattern = new SplashFunctionPattern(colorMode, state, shading);
   double xMin, yMin, xMax, yMax;
-  SplashPath *path;
   GBool vaa = getVectorAntialias();
   // restore vector antialias because we support it here
   setVectorAntialias(gTrue);
@@ -4896,17 +4876,16 @@ GBool SplashOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *s
   state->lineTo(xMax, yMax);
   state->lineTo(xMin, yMax);
   state->closePath();
-  path = convertPath(state, state->getPath(), gTrue);
+  SplashPath path = convertPath(state, state->getPath(), gTrue);
 
 #ifdef SPLASH_CMYK
   pattern->getShading()->getColorSpace()->createMapping(bitmap->getSeparationList(), SPOT_NCOMPS);
 #endif
   setOverprintMask(pattern->getShading()->getColorSpace(), state->getFillOverprint(),
 		   state->getOverprintMode(), nullptr);
-  retVal = (splash->shadedFill(path, pattern->getShading()->getHasBBox(), pattern) == splashOk);
+  retVal = (splash->shadedFill(&path, pattern->getShading()->getHasBBox(), pattern) == splashOk);
   state->clearPath();
   setVectorAntialias(vaa);
-  delete path;
 
   delete pattern;
 
diff --git a/poppler/SplashOutputDev.h b/poppler/SplashOutputDev.h
index 3a1b594e..ee4220a4 100644
--- a/poppler/SplashOutputDev.h
+++ b/poppler/SplashOutputDev.h
@@ -410,7 +410,7 @@ private:
   static void getMatteColor( SplashColorMode colorMode, GfxImageColorMap *colorMap, GfxColor * matteColor, SplashColor splashMatteColor);
   void setOverprintMask(GfxColorSpace *colorSpace, GBool overprintFlag,
 			int overprintMode, GfxColor *singleColor, GBool grayIndexed = gFalse);
-  SplashPath *convertPath(GfxState *state, GfxPath *path,
+  SplashPath convertPath(GfxState *state, GfxPath *path,
 			  GBool dropEmptySubpaths);
   void drawType3Glyph(GfxState *state, T3FontCache *t3Font,
 		      T3FontCacheTag *tag, Guchar *data);
commit a31a9e1b9a1eefcea4c8e08f2d84deb0ac6cc4ae
Author: Stefan Brüns <stefan.bruens at rwth-aachen.de>
Date:   Fri Aug 31 00:23:32 2018 +0200

    SplashPath: Add move constructor
    
    After moving, the new SplashPath is in the same state as it
    has been copy constructed, the moved from is in the same
    state as default constructed, i.e. empty.

diff --git a/splash/SplashPath.cc b/splash/SplashPath.cc
index 20acd40b..188279e8 100644
--- a/splash/SplashPath.cc
+++ b/splash/SplashPath.cc
@@ -72,6 +72,23 @@ SplashPath::SplashPath(SplashPath *path) {
   }
 }
 
+SplashPath::SplashPath(SplashPath&& path) {
+  length = path.length;
+  size = path.size;
+  pts = path.pts;
+  flags = path.flags;
+  curSubpath = path.curSubpath;
+
+  hints = path.hints;
+  hintsLength = hintsSize = path.hintsLength;
+
+  path.pts = nullptr;
+  path.flags = nullptr;
+  path.length = path.size = 0;
+  path.hints = nullptr;
+  path.hintsLength = path.hintsSize = 0;
+}
+
 SplashPath::~SplashPath() {
   gfree(pts);
   gfree(flags);
diff --git a/splash/SplashPath.h b/splash/SplashPath.h
index 54331372..96dbb6e0 100644
--- a/splash/SplashPath.h
+++ b/splash/SplashPath.h
@@ -79,6 +79,7 @@ public:
 
   SplashPath(const SplashPath&) = delete;
   SplashPath& operator=(const SplashPath&) = delete;
+  SplashPath(SplashPath&& path);
 
   // Append <path> to <this>.
   void append(SplashPath *path);
commit 2190b9997ac786189368fc03e46e540c308f11b5
Author: Stefan Brüns <stefan.bruens at rwth-aachen.de>
Date:   Wed Aug 29 00:21:57 2018 +0200

    Allocate temporary SplashXPath on the stack
    
    SplashXPath is only used inside the each fill function, but newer
    passed to the outside. As it is small, there is no reason not to
    allocate it on the stack.

diff --git a/splash/Splash.cc b/splash/Splash.cc
index 7c08a6f7..9d356b99 100644
--- a/splash/Splash.cc
+++ b/splash/Splash.cc
@@ -2107,7 +2107,6 @@ SplashError Splash::stroke(SplashPath *path) {
 
 void Splash::strokeNarrow(SplashPath *path) {
   SplashPipe pipe;
-  SplashXPath *xPath;
   SplashXPathSeg *seg;
   int x0, x1, y0, y1, xa, xb, y;
   SplashCoord dxdy;
@@ -2117,13 +2116,13 @@ void Splash::strokeNarrow(SplashPath *path) {
 
   nClipRes[0] = nClipRes[1] = nClipRes[2] = 0;
 
-  xPath = new SplashXPath(path, state->matrix, state->flatness, gFalse);
+  SplashXPath xPath(path, state->matrix, state->flatness, gFalse);
 
   pipeInit(&pipe, 0, 0, state->strokePattern, nullptr,
 	   (Guchar)splashRound(state->strokeAlpha * 255),
 	   gFalse, gFalse);
 
-  for (i = 0, seg = xPath->segs; i < xPath->length; ++i, ++seg) {
+  for (i = 0, seg = xPath.segs; i < xPath.length; ++i, ++seg) {
     if (seg->y0 <= seg->y1) {
       y0 = splashFloor(seg->y0);
       y1 = splashFloor(seg->y1);
@@ -2199,8 +2198,6 @@ void Splash::strokeNarrow(SplashPath *path) {
   } else {
     opClipRes = splashClipAllOutside;
   }
-
-  delete xPath;
 }
 
 void Splash::strokeWide(SplashPath *path, SplashCoord w) {
@@ -2494,7 +2491,6 @@ SplashError Splash::fillWithPattern(SplashPath *path, GBool eo,
 				    SplashPattern *pattern,
 				    SplashCoord alpha) {
   SplashPipe pipe = {};
-  SplashXPath *xPath;
   SplashXPathScanner *scanner;
   int xMinI, yMinI, xMaxI, yMaxI, x0, x1, y;
   SplashClipResult clipRes, clipRes2;
@@ -2548,19 +2544,19 @@ SplashError Splash::fillWithPattern(SplashPath *path, GBool eo,
     }
   }
 
-  xPath = new SplashXPath(path, state->matrix, state->flatness, gTrue, 
+  SplashXPath xPath(path, state->matrix, state->flatness, gTrue,
     adjustLine, linePosI);
   if (vectorAntialias && !inShading) {
-    xPath->aaScale();
+    xPath.aaScale();
   }
-  xPath->sort();
+  xPath.sort();
   yMinI = state->clip->getYMinI();
   yMaxI = state->clip->getYMaxI();
   if (vectorAntialias && !inShading) {
     yMinI = yMinI * splashAASize;
     yMaxI = (yMaxI + 1) * splashAASize - 1;
   }
-  scanner = new SplashXPathScanner(xPath, eo, yMinI, yMaxI);
+  scanner = new SplashXPathScanner(&xPath, eo, yMinI, yMaxI);
 
   // get the min and max x and y values
   if (vectorAntialias && !inShading) {
@@ -2576,7 +2572,6 @@ SplashError Splash::fillWithPattern(SplashPath *path, GBool eo,
     if (delta < 0.2) {
       opClipRes = splashClipAllOutside;
       delete scanner;
-      delete xPath;
       return splashOk;
     }
   }
@@ -2633,7 +2628,6 @@ SplashError Splash::fillWithPattern(SplashPath *path, GBool eo,
   opClipRes = clipRes;
 
   delete scanner;
-  delete xPath;
   return splashOk;
 }
 
@@ -2706,7 +2700,6 @@ GBool Splash::pathAllOutside(SplashPath *path) {
 
 SplashError Splash::xorFill(SplashPath *path, GBool eo) {
   SplashPipe pipe;
-  SplashXPath *xPath;
   SplashXPathScanner *scanner;
   int xMinI, yMinI, xMaxI, yMaxI, x0, x1, y;
   SplashClipResult clipRes, clipRes2;
@@ -2715,9 +2708,9 @@ SplashError Splash::xorFill(SplashPath *path, GBool eo) {
   if (path->length == 0) {
     return splashErrEmptyPath;
   }
-  xPath = new SplashXPath(path, state->matrix, state->flatness, gTrue);
-  xPath->sort();
-  scanner = new SplashXPathScanner(xPath, eo, state->clip->getYMinI(),
+  SplashXPath xPath(path, state->matrix, state->flatness, gTrue);
+  xPath.sort();
+  scanner = new SplashXPathScanner(&xPath, eo, state->clip->getYMinI(),
 				   state->clip->getYMaxI());
 
   // get the min and max x and y values
@@ -2757,7 +2750,6 @@ SplashError Splash::xorFill(SplashPath *path, GBool eo) {
   opClipRes = clipRes;
 
   delete scanner;
-  delete xPath;
   return splashOk;
 }
 
@@ -6392,7 +6384,6 @@ void Splash::dumpXPath(SplashXPath *path) {
 SplashError Splash::shadedFill(SplashPath *path, GBool hasBBox,
                                SplashPattern *pattern) {
   SplashPipe pipe;
-  SplashXPath *xPath;
   SplashXPathScanner *scanner;
   int xMinI, yMinI, xMaxI, yMaxI, x0, x1, y;
   SplashClipResult clipRes;
@@ -6403,18 +6394,18 @@ SplashError Splash::shadedFill(SplashPath *path, GBool hasBBox,
   if (path->length == 0) {
     return splashErrEmptyPath;
   }
-  xPath = new SplashXPath(path, state->matrix, state->flatness, gTrue);
+  SplashXPath xPath(path, state->matrix, state->flatness, gTrue);
   if (vectorAntialias) {
-    xPath->aaScale();
+    xPath.aaScale();
   }
-  xPath->sort();
+  xPath.sort();
   yMinI = state->clip->getYMinI();
   yMaxI = state->clip->getYMaxI();
   if (vectorAntialias && !inShading) {
     yMinI = yMinI * splashAASize;
     yMaxI = (yMaxI + 1) * splashAASize - 1;
   }
-  scanner = new SplashXPathScanner(xPath, gFalse, yMinI, yMaxI);
+  scanner = new SplashXPathScanner(&xPath, gFalse, yMinI, yMaxI);
 
   // get the min and max x and y values
   if (vectorAntialias) {
@@ -6517,6 +6508,5 @@ SplashError Splash::shadedFill(SplashPath *path, GBool hasBBox,
   opClipRes = clipRes;
 
   delete scanner;
-  delete xPath;
   return splashOk;
 }


More information about the poppler mailing list