[poppler] [PATCH v2 1/5] Splash: Reserve space for path segments upfront
Stefan BrĂ¼ns
stefan.bruens at rwth-aachen.de
Sat May 26 17:51:20 UTC 2018
Instead of iteratively growing the array reserve sufficient space
prior to populating the array.
---
poppler/SplashOutputDev.cc | 1 +
splash/SplashPath.cc | 4 ++++
splash/SplashPath.h | 3 +++
3 files changed, 8 insertions(+)
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index b85a860c..ae93bddd 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -2368,6 +2368,7 @@ SplashPath *SplashOutputDev::convertPath(GfxState *state, GfxPath *path,
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),
(SplashCoord)subpath->getY(0));
j = 1;
diff --git a/splash/SplashPath.cc b/splash/SplashPath.cc
index 09b2a76e..4a00e959 100644
--- a/splash/SplashPath.cc
+++ b/splash/SplashPath.cc
@@ -62,6 +62,10 @@ SplashPath::~SplashPath() {
gfree(hints);
}
+void SplashPath::reserve(int nPts) {
+ grow(nPts - size);
+}
+
// Add space for <nPts> more points.
void SplashPath::grow(int nPts) {
if (length + nPts > size) {
diff --git a/splash/SplashPath.h b/splash/SplashPath.h
index c8164a8b..c85303a8 100644
--- a/splash/SplashPath.h
+++ b/splash/SplashPath.h
@@ -115,6 +115,9 @@ public:
// Get the current point.
GBool getCurPt(SplashCoord *x, SplashCoord *y);
+ // Reserve space for at least n points
+ void reserve(int n);
+
protected:
SplashPath(SplashPath *path);
--
2.16.3
More information about the poppler
mailing list