summaryrefslogtreecommitdiff
path: root/splash
diff options
context:
space:
mode:
authorStefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>2018-08-27 02:29:20 +0200
committerAlbert Astals Cid <aacid@kde.org>2019-07-21 23:59:22 +0200
commit355fd8d58ca0209284fe568b3add28f207e995c1 (patch)
treec498812a946f312bae2ef428131537c4aa08cba1 /splash
parent3348f4d3cdd625b47c3a63b86f9329df3363e29f (diff)
SplashXPathScanner: Optionally use small_vector from boost
Currently, each row in the intersections vector is allocated separately, when the first intersection is added. To avoid these allocations for common simple polygons, boost::container::small_vector<4, T> is used, which stores up to 4 intersections inline. small_vector is a header-only class. For the documents from #57 (fdo#96728) and #24 (fdo#78728), the runtime/memory is significantly reduced (according to /usr/bin/time -v): (1) $> pdftoppm -r 18 -aa no runsforever-poppler.pdf (2) $> pdftoppm surf-types.pdf Before/After runsforever-poppler | surf-types User time (seconds): 2348.08 / 1773.53 | 7.76 / 5.02 Maximum resident set size (kbytes): 46288 / 45896 | 14076 / 13748
Diffstat (limited to 'splash')
-rw-r--r--splash/SplashXPathScanner.cc2
-rw-r--r--splash/SplashXPathScanner.h14
2 files changed, 16 insertions, 0 deletions
diff --git a/splash/SplashXPathScanner.cc b/splash/SplashXPathScanner.cc
index e8abe94c..042a6ef6 100644
--- a/splash/SplashXPathScanner.cc
+++ b/splash/SplashXPathScanner.cc
@@ -344,9 +344,11 @@ bool SplashXPathScanner::addIntersection(double segYMin, double segYMax,
}
auto& line = allIntersections[y - yMin];
+#ifndef USE_BOOST_HEADERS
if (line.empty()) {
line.reserve(4);
}
+#endif
line.push_back(intersect);
return true;
diff --git a/splash/SplashXPathScanner.h b/splash/SplashXPathScanner.h
index 1ac8ce84..88b9d8c9 100644
--- a/splash/SplashXPathScanner.h
+++ b/splash/SplashXPathScanner.h
@@ -25,6 +25,12 @@
#include "SplashTypes.h"
+#include <poppler-config.h>
+
+#ifdef USE_BOOST_HEADERS
+#include <boost/container/small_vector.hpp>
+#endif
+
#include <vector>
class SplashXPath;
@@ -94,7 +100,11 @@ private:
int xMin, yMin, xMax, yMax;
bool partialClip;
+#ifdef USE_BOOST_HEADERS
+ typedef boost::container::small_vector<SplashIntersect, 4> IntersectionLine;
+#else
typedef std::vector<SplashIntersect> IntersectionLine;
+#endif
std::vector<IntersectionLine> allIntersections;
friend class SplashXPathScanIterator;
@@ -109,7 +119,11 @@ public:
bool getNextSpan(int *x0, int *x1);
private:
+#ifdef USE_BOOST_HEADERS
+ typedef boost::container::small_vector<SplashIntersect, 4> IntersectionLine;
+#else
typedef std::vector<SplashIntersect> IntersectionLine;
+#endif
const IntersectionLine &line;
size_t interIdx; // current index into <line>