[poppler] splash/SplashClip.cc splash/SplashClip.h splash/SplashXPathScanner.cc splash/SplashXPathScanner.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Aug 27 10:22:31 UTC 2021


 splash/SplashClip.cc         |   13 +++----------
 splash/SplashClip.h          |    5 ++++-
 splash/SplashXPathScanner.cc |   11 -----------
 splash/SplashXPathScanner.h  |    6 ------
 4 files changed, 7 insertions(+), 28 deletions(-)

New commits:
commit 849e4bbbdcffe8c7ec4fe319f7cf1fbbd8c84949
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Aug 27 02:12:27 2021 +0200

    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.

diff --git a/splash/SplashClip.cc b/splash/SplashClip.cc
index 06a5229a..3657f59f 100644
--- a/splash/SplashClip.cc
+++ b/splash/SplashClip.cc
@@ -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;
     }
 
diff --git a/splash/SplashClip.h b/splash/SplashClip.h
index 7e88e64c..c98fe3ba 100644
--- a/splash/SplashClip.h
+++ b/splash/SplashClip.h
@@ -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;
 };
 
diff --git a/splash/SplashXPathScanner.cc b/splash/SplashXPathScanner.cc
index 238e5fcb..f9444d0d 100644
--- a/splash/SplashXPathScanner.cc
+++ b/splash/SplashXPathScanner.cc
@@ -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
diff --git a/splash/SplashXPathScanner.h b/splash/SplashXPathScanner.h
index 643b06f3..fc9c6a00 100644
--- a/splash/SplashXPathScanner.h
+++ b/splash/SplashXPathScanner.h
@@ -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);


More information about the poppler mailing list