splash/Splash.cc | 6 ++--- splash/SplashClip.cc | 45 +++++++++++-------------------------------- splash/SplashClip.h | 1 splash/SplashXPath.cc | 8 ------- splash/SplashXPath.h | 4 --- splash/SplashXPathScanner.cc | 20 +++++++++---------- splash/SplashXPathScanner.h | 4 +-- 7 files changed, 27 insertions(+), 61 deletions(-)
New commits: commit 875be6054ff85261e254268a77cf47ebb9c539e9 Author: Albert Astals Cid <[email protected]> Date: Fri Aug 27 13:33:05 2021 +0200 SplashClip: we don't need to keep the paths around Since we never used them for anything ^_^ Saves yet another 40% in file from issue #1126 diff --git a/splash/Splash.cc b/splash/Splash.cc index 3669874d..73fc9f7e 100644 --- a/splash/Splash.cc +++ b/splash/Splash.cc @@ -2367,7 +2367,7 @@ SplashError Splash::fillWithPattern(SplashPath *path, bool eo, SplashPattern *pa yMinI = yMinI * splashAASize; yMaxI = (yMaxI + 1) * splashAASize - 1; } - SplashXPathScanner scanner(&xPath, eo, yMinI, yMaxI); + SplashXPathScanner scanner(xPath, eo, yMinI, yMaxI); // get the min and max x and y values if (vectorAntialias && !inShading) { @@ -2518,7 +2518,7 @@ SplashError Splash::xorFill(SplashPath *path, bool eo) } SplashXPath xPath(path, state->matrix, state->flatness, true); xPath.sort(); - SplashXPathScanner scanner(&xPath, eo, state->clip->getYMinI(), state->clip->getYMaxI()); + SplashXPathScanner scanner(xPath, eo, state->clip->getYMinI(), state->clip->getYMaxI()); // get the min and max x and y values scanner.getBBox(&xMinI, &yMinI, &xMaxI, &yMaxI); @@ -6118,7 +6118,7 @@ SplashError Splash::shadedFill(SplashPath *path, bool hasBBox, SplashPattern *pa yMinI = yMinI * splashAASize; yMaxI = (yMaxI + 1) * splashAASize - 1; } - SplashXPathScanner scanner(&xPath, false, yMinI, yMaxI); + SplashXPathScanner scanner(xPath, false, yMinI, yMaxI); // get the min and max x and y values if (vectorAntialias) { diff --git a/splash/SplashClip.cc b/splash/SplashClip.cc index 3657f59f..0620c2c0 100644 --- a/splash/SplashClip.cc +++ b/splash/SplashClip.cc @@ -64,7 +64,6 @@ SplashClip::SplashClip(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoo yMinI = splashFloor(yMin); xMaxI = splashCeil(xMax) - 1; yMaxI = splashCeil(yMax) - 1; - paths = nullptr; flags = nullptr; length = size = 0; } @@ -84,23 +83,15 @@ SplashClip::SplashClip(const SplashClip *clip) yMaxI = clip->yMaxI; length = clip->length; size = clip->size; - paths = (SplashXPath **)gmallocn(size, sizeof(SplashXPath *)); flags = (unsigned char *)gmallocn(size, sizeof(unsigned char)); scanners = clip->scanners; for (i = 0; i < length; ++i) { - paths[i] = clip->paths[i]->copy(); flags[i] = clip->flags[i]; } } SplashClip::~SplashClip() { - int i; - - for (i = 0; i < length; ++i) { - delete paths[i]; - } - gfree(paths); gfree(flags); } @@ -113,21 +104,13 @@ void SplashClip::grow(int nPaths) while (size < length + nPaths) { size *= 2; } - paths = (SplashXPath **)greallocn(paths, size, sizeof(SplashXPath *)); flags = (unsigned char *)greallocn(flags, size, sizeof(unsigned char)); } } void SplashClip::resetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1) { - int i; - - for (i = 0; i < length; ++i) { - delete paths[i]; - } - gfree(paths); gfree(flags); - paths = nullptr; flags = nullptr; scanners = {}; length = size = 0; @@ -197,37 +180,33 @@ SplashError SplashClip::clipToRect(SplashCoord x0, SplashCoord y0, SplashCoord x SplashError SplashClip::clipToPath(SplashPath *path, SplashCoord *matrix, SplashCoord flatness, bool eo) { - SplashXPath *xPath; int yMinAA, yMaxAA; - xPath = new SplashXPath(path, matrix, flatness, true); + SplashXPath xPath(path, matrix, flatness, true); // check for an empty path - if (xPath->length == 0) { + if (xPath.length == 0) { xMax = xMin - 1; yMax = yMin - 1; xMaxI = splashCeil(xMax) - 1; yMaxI = splashCeil(yMax) - 1; - delete xPath; // check for a rectangle - } else if (xPath->length == 4 - && ((xPath->segs[0].x0 == xPath->segs[0].x1 && xPath->segs[0].x0 == xPath->segs[1].x0 && xPath->segs[0].x0 == xPath->segs[3].x1 && xPath->segs[2].x0 == xPath->segs[2].x1 && xPath->segs[2].x0 == xPath->segs[1].x1 - && xPath->segs[2].x0 == xPath->segs[3].x0 && xPath->segs[1].y0 == xPath->segs[1].y1 && xPath->segs[1].y0 == xPath->segs[0].y1 && xPath->segs[1].y0 == xPath->segs[2].y0 && xPath->segs[3].y0 == xPath->segs[3].y1 - && xPath->segs[3].y0 == xPath->segs[0].y0 && xPath->segs[3].y0 == xPath->segs[2].y1) - || (xPath->segs[0].y0 == xPath->segs[0].y1 && xPath->segs[0].y0 == xPath->segs[1].y0 && xPath->segs[0].y0 == xPath->segs[3].y1 && xPath->segs[2].y0 == xPath->segs[2].y1 && xPath->segs[2].y0 == xPath->segs[1].y1 - && xPath->segs[2].y0 == xPath->segs[3].y0 && xPath->segs[1].x0 == xPath->segs[1].x1 && xPath->segs[1].x0 == xPath->segs[0].x1 && xPath->segs[1].x0 == xPath->segs[2].x0 && xPath->segs[3].x0 == xPath->segs[3].x1 - && xPath->segs[3].x0 == xPath->segs[0].x0 && xPath->segs[3].x0 == xPath->segs[2].x1))) { - clipToRect(xPath->segs[0].x0, xPath->segs[0].y0, xPath->segs[2].x0, xPath->segs[2].y0); - delete xPath; + } else if (xPath.length == 4 + && ((xPath.segs[0].x0 == xPath.segs[0].x1 && xPath.segs[0].x0 == xPath.segs[1].x0 && xPath.segs[0].x0 == xPath.segs[3].x1 && xPath.segs[2].x0 == xPath.segs[2].x1 && xPath.segs[2].x0 == xPath.segs[1].x1 + && xPath.segs[2].x0 == xPath.segs[3].x0 && xPath.segs[1].y0 == xPath.segs[1].y1 && xPath.segs[1].y0 == xPath.segs[0].y1 && xPath.segs[1].y0 == xPath.segs[2].y0 && xPath.segs[3].y0 == xPath.segs[3].y1 + && xPath.segs[3].y0 == xPath.segs[0].y0 && xPath.segs[3].y0 == xPath.segs[2].y1) + || (xPath.segs[0].y0 == xPath.segs[0].y1 && xPath.segs[0].y0 == xPath.segs[1].y0 && xPath.segs[0].y0 == xPath.segs[3].y1 && xPath.segs[2].y0 == xPath.segs[2].y1 && xPath.segs[2].y0 == xPath.segs[1].y1 + && xPath.segs[2].y0 == xPath.segs[3].y0 && xPath.segs[1].x0 == xPath.segs[1].x1 && xPath.segs[1].x0 == xPath.segs[0].x1 && xPath.segs[1].x0 == xPath.segs[2].x0 && xPath.segs[3].x0 == xPath.segs[3].x1 + && xPath.segs[3].x0 == xPath.segs[0].x0 && xPath.segs[3].x0 == xPath.segs[2].x1))) { + clipToRect(xPath.segs[0].x0, xPath.segs[0].y0, xPath.segs[2].x0, xPath.segs[2].y0); } else { grow(1); if (antialias) { - xPath->aaScale(); + xPath.aaScale(); } - xPath->sort(); - paths[length] = xPath; + xPath.sort(); flags[length] = eo ? splashClipEO : 0; if (antialias) { yMinAA = yMinI * splashAASize; diff --git a/splash/SplashClip.h b/splash/SplashClip.h index c98fe3ba..74dc616d 100644 --- a/splash/SplashClip.h +++ b/splash/SplashClip.h @@ -123,7 +123,6 @@ protected: bool antialias; SplashCoord xMin, yMin, xMax, yMax; int xMinI, yMinI, xMaxI, yMaxI; - SplashXPath **paths; unsigned char *flags; std::vector<std::shared_ptr<SplashXPathScanner>> scanners; int length, size; diff --git a/splash/SplashXPath.cc b/splash/SplashXPath.cc index 02f2f16d..895dddfb 100644 --- a/splash/SplashXPath.cc +++ b/splash/SplashXPath.cc @@ -242,14 +242,6 @@ void SplashXPath::strokeAdjust(SplashXPathAdjust *adjust, SplashCoord *xp, Splas } } -SplashXPath::SplashXPath(const SplashXPath *xPath) -{ - length = xPath->length; - size = xPath->size; - segs = (SplashXPathSeg *)gmallocn(size, sizeof(SplashXPathSeg)); - memcpy(segs, xPath->segs, length * sizeof(SplashXPathSeg)); -} - SplashXPath::~SplashXPath() { gfree(segs); diff --git a/splash/SplashXPath.h b/splash/SplashXPath.h index a5bcd487..e59649fa 100644 --- a/splash/SplashXPath.h +++ b/splash/SplashXPath.h @@ -65,9 +65,6 @@ public: // subpaths. SplashXPath(SplashPath *path, SplashCoord *matrix, SplashCoord flatness, bool closeSubpaths, bool adjustLines = false, int linePosI = 0); - // Copy an expanded path. - SplashXPath *copy() const { return new SplashXPath(this); } - ~SplashXPath(); SplashXPath(const SplashXPath &) = delete; @@ -81,7 +78,6 @@ public: void sort(); protected: - SplashXPath(const SplashXPath *xPath); void transform(SplashCoord *matrix, SplashCoord xi, SplashCoord yi, SplashCoord *xo, SplashCoord *yo); void strokeAdjust(SplashXPathAdjust *adjust, SplashCoord *xp, SplashCoord *yp); void grow(int nSegs); diff --git a/splash/SplashXPathScanner.cc b/splash/SplashXPathScanner.cc index f9444d0d..e32fdb4f 100644 --- a/splash/SplashXPathScanner.cc +++ b/splash/SplashXPathScanner.cc @@ -38,9 +38,9 @@ // SplashXPathScanner //------------------------------------------------------------------------ -SplashXPathScanner::SplashXPathScanner(const SplashXPath *xPath, bool eoA, int clipYMin, int clipYMax) +SplashXPathScanner::SplashXPathScanner(const SplashXPath &xPath, bool eoA, int clipYMin, int clipYMax) { - SplashXPathSeg *seg; + const SplashXPathSeg *seg; SplashCoord xMinFP, yMinFP, xMaxFP, yMaxFP; int i; @@ -50,8 +50,8 @@ SplashXPathScanner::SplashXPathScanner(const SplashXPath *xPath, bool eoA, int c // compute the bbox xMin = yMin = 1; xMax = yMax = 0; - if (xPath->length > 0) { - seg = &xPath->segs[0]; + if (xPath.length > 0) { + seg = &xPath.segs[0]; if (unlikely(std::isnan(seg->x0) || std::isnan(seg->x1) || std::isnan(seg->y0) || std::isnan(seg->y1))) { return; } @@ -69,8 +69,8 @@ SplashXPathScanner::SplashXPathScanner(const SplashXPath *xPath, bool eoA, int c yMinFP = seg->y0; yMaxFP = seg->y1; } - for (i = 1; i < xPath->length; ++i) { - seg = &xPath->segs[i]; + for (i = 1; i < xPath.length; ++i) { + seg = &xPath.segs[i]; if (unlikely(std::isnan(seg->x0) || std::isnan(seg->x1) || std::isnan(seg->y0) || std::isnan(seg->y1))) { return; } @@ -224,9 +224,9 @@ SplashXPathScanIterator::SplashXPathScanIterator(const SplashXPathScanner &scann } } -void SplashXPathScanner::computeIntersections(const SplashXPath *xPath) +void SplashXPathScanner::computeIntersections(const SplashXPath &xPath) { - SplashXPathSeg *seg; + const SplashXPathSeg *seg; SplashCoord segXMin, segXMax, segYMin, segYMax, xx0, xx1; int x, y, y0, y1, i; @@ -237,8 +237,8 @@ void SplashXPathScanner::computeIntersections(const SplashXPath *xPath) // build the list of all intersections allIntersections.resize(yMax - yMin + 1); - for (i = 0; i < xPath->length; ++i) { - seg = &xPath->segs[i]; + for (i = 0; i < xPath.length; ++i) { + seg = &xPath.segs[i]; if (seg->flags & splashXPathFlip) { segYMin = seg->y1; segYMax = seg->y0; diff --git a/splash/SplashXPathScanner.h b/splash/SplashXPathScanner.h index fc9c6a00..476e98c9 100644 --- a/splash/SplashXPathScanner.h +++ b/splash/SplashXPathScanner.h @@ -51,7 +51,7 @@ class SplashXPathScanner { public: // Create a new SplashXPathScanner object. <xPathA> must be sorted. - SplashXPathScanner(const SplashXPath *xPath, bool eoA, int clipYMin, int clipYMax); + SplashXPathScanner(const SplashXPath &xPath, bool eoA, int clipYMin, int clipYMax); ~SplashXPathScanner(); @@ -94,7 +94,7 @@ public: void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y) const; private: - void computeIntersections(const SplashXPath *xPath); + void computeIntersections(const SplashXPath &xPath); bool addIntersection(double segYMin, double segYMax, int y, int x0, int x1, int count); bool eo;
