Commit 849e4bbb authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Splash: huge speed improvement in save/restore heavy files

27 secs to 2 secs in file from issue #1126 in my computer

When copying the SplashClip we don't need to copy the scanners, we can
just share the same pointers since once created the scanners can't
change.
parent 0f78fc2f
Pipeline #389778 passed with stages
in 7 minutes and 29 seconds
......@@ -66,7 +66,6 @@ SplashClip::SplashClip(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoo
yMaxI = splashCeil(yMax) - 1;
paths = nullptr;
flags = nullptr;
scanners = nullptr;
length = size = 0;
}
......@@ -87,11 +86,10 @@ SplashClip::SplashClip(const SplashClip *clip)
size = clip->size;
paths = (SplashXPath **)gmallocn(size, sizeof(SplashXPath *));
flags = (unsigned char *)gmallocn(size, sizeof(unsigned char));
scanners = (SplashXPathScanner **)gmallocn(size, sizeof(SplashXPathScanner *));
scanners = clip->scanners;
for (i = 0; i < length; ++i) {
paths[i] = clip->paths[i]->copy();
flags[i] = clip->flags[i];
scanners[i] = clip->scanners[i]->copy();
}
}
......@@ -101,11 +99,9 @@ SplashClip::~SplashClip()
for (i = 0; i < length; ++i) {
delete paths[i];
delete scanners[i];
}
gfree(paths);
gfree(flags);
gfree(scanners);
}
void SplashClip::grow(int nPaths)
......@@ -119,7 +115,6 @@ void SplashClip::grow(int nPaths)
}
paths = (SplashXPath **)greallocn(paths, size, sizeof(SplashXPath *));
flags = (unsigned char *)greallocn(flags, size, sizeof(unsigned char));
scanners = (SplashXPathScanner **)greallocn(scanners, size, sizeof(SplashXPathScanner *));
}
}
......@@ -129,14 +124,12 @@ void SplashClip::resetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, Spl
for (i = 0; i < length; ++i) {
delete paths[i];
delete scanners[i];
}
gfree(paths);
gfree(flags);
gfree(scanners);
paths = nullptr;
flags = nullptr;
scanners = nullptr;
scanners = {};
length = size = 0;
if (x0 < x1) {
......@@ -243,7 +236,7 @@ SplashError SplashClip::clipToPath(SplashPath *path, SplashCoord *matrix, Splash
yMinAA = yMinI;
yMaxAA = yMaxI;
}
scanners[length] = new SplashXPathScanner(xPath, eo, yMinAA, yMaxAA);
scanners.emplace_back(std::make_shared<SplashXPathScanner>(xPath, eo, yMinAA, yMaxAA));
++length;
}
......
......@@ -25,6 +25,9 @@
#include "SplashTypes.h"
#include <memory>
#include <vector>
class SplashPath;
class SplashXPath;
class SplashXPathScanner;
......@@ -122,7 +125,7 @@ protected:
int xMinI, yMinI, xMaxI, yMaxI;
SplashXPath **paths;
unsigned char *flags;
SplashXPathScanner **scanners;
std::vector<std::shared_ptr<SplashXPathScanner>> scanners;
int length, size;
};
......
......@@ -111,17 +111,6 @@ SplashXPathScanner::SplashXPathScanner(const SplashXPath *xPath, bool eoA, int c
computeIntersections(xPath);
}
SplashXPathScanner::SplashXPathScanner(const SplashXPathScanner *scanner)
{
eo = scanner->eo;
xMin = scanner->xMin;
yMin = scanner->yMin;
xMax = scanner->xMax;
yMax = scanner->yMax;
partialClip = scanner->partialClip;
allIntersections = scanner->allIntersections;
}
SplashXPathScanner::~SplashXPathScanner() { }
void SplashXPathScanner::getBBoxAA(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA) const
......
......@@ -53,9 +53,6 @@ public:
// Create a new SplashXPathScanner object. <xPathA> must be sorted.
SplashXPathScanner(const SplashXPath *xPath, bool eoA, int clipYMin, int clipYMax);
// Copy a scanner.
SplashXPathScanner *copy() const { return new SplashXPathScanner(this); }
~SplashXPathScanner();
SplashXPathScanner(const SplashXPathScanner &) = delete;
......@@ -96,9 +93,6 @@ public:
// will update <x0> and <x1>.
void clipAALine(SplashBitmap *aaBuf, int *x0, int *x1, int y) const;
protected:
SplashXPathScanner(const SplashXPathScanner *scanner);
private:
void computeIntersections(const SplashXPath *xPath);
bool addIntersection(double segYMin, double segYMax, int y, int x0, int x1, int count);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment