[poppler] poppler/GfxFont.cc splash/SplashXPath.cc splash/SplashXPathScanner.cc
Albert Astals Cid
aacid at kemper.freedesktop.org
Sun Sep 5 04:33:17 PDT 2010
poppler/GfxFont.cc | 17 ++++++---------
splash/SplashXPath.cc | 48 +++++++++++++++++++++++++++----------------
splash/SplashXPathScanner.cc | 10 +++++---
3 files changed, 44 insertions(+), 31 deletions(-)
New commits:
commit 0d96f74f31171c58a55e4ac36d492ce36dd5e7c5
Author: Albert Astals Cid <aacid at kde.org>
Date: Sun Sep 5 12:31:57 2010 +0100
Use std::sort instead of qsort
Gives a nice speed improvement without any real code change
Passes regression tests
Based on PaweÅ Wiejacha patches
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 9b72d34..2d7180a 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -38,6 +38,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <algorithm>
#include "goo/gmem.h"
#include "Error.h"
#include "Object.h"
@@ -1299,14 +1300,12 @@ Dict *Gfx8BitFont::getResources() {
// GfxCIDFont
//------------------------------------------------------------------------
-static int CDECL cmpWidthExcep(const void *w1, const void *w2) {
- return ((GfxFontCIDWidthExcep *)w1)->first -
- ((GfxFontCIDWidthExcep *)w2)->first;
+static bool cmpWidthExcep(const GfxFontCIDWidthExcep &w1, const GfxFontCIDWidthExcep &w2) {
+ return w1.first < w2.first;
}
-static int CDECL cmpWidthExcepV(const void *w1, const void *w2) {
- return ((GfxFontCIDWidthExcepV *)w1)->first -
- ((GfxFontCIDWidthExcepV *)w2)->first;
+static bool cmpWidthExcepV(const GfxFontCIDWidthExcepV &w1, const GfxFontCIDWidthExcepV &w2) {
+ return w1.first < w2.first;
}
GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
@@ -1567,8 +1566,7 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
obj3.free();
obj2.free();
}
- qsort(widths.exceps, widths.nExceps, sizeof(GfxFontCIDWidthExcep),
- &cmpWidthExcep);
+ std::sort(widths.exceps, widths.exceps + widths.nExceps, &cmpWidthExcep);
}
obj1.free();
@@ -1651,8 +1649,7 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
obj3.free();
obj2.free();
}
- qsort(widths.excepsV, widths.nExcepsV, sizeof(GfxFontCIDWidthExcepV),
- &cmpWidthExcepV);
+ std::sort(widths.excepsV, widths.excepsV + widths.nExcepsV, &cmpWidthExcepV);
}
obj1.free();
diff --git a/splash/SplashXPath.cc b/splash/SplashXPath.cc
index d7e114d..d558935 100644
--- a/splash/SplashXPath.cc
+++ b/splash/SplashXPath.cc
@@ -4,6 +4,21 @@
//
//========================================================================
+//========================================================================
+//
+// Modified under the Poppler project - http://poppler.freedesktop.org
+//
+// All changes made under the Poppler project to this file are licensed
+// under GPL version 2 or later
+//
+// Copyright (C) 2010 PaweÅ Wiejacha <pawel.wiejacha at gmail.com>
+// Copyright (C) 2010 Albert Astals Cid <aacid at kde.org>
+//
+// To see a description of the changes please see the Changelog file that
+// came with your tarball or type make ChangeLog if you are building from git
+//
+//========================================================================
+
#include <config.h>
#ifdef USE_GCC_PRAGMAS
@@ -12,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include <algorithm>
#include "goo/gmem.h"
#include "SplashMath.h"
#include "SplashPath.h"
@@ -398,32 +414,30 @@ void SplashXPath::addSegment(SplashCoord x0, SplashCoord y0,
++length;
}
-static int cmpXPathSegs(const void *arg0, const void *arg1) {
- SplashXPathSeg *seg0 = (SplashXPathSeg *)arg0;
- SplashXPathSeg *seg1 = (SplashXPathSeg *)arg1;
+static bool cmpXPathSegs(const SplashXPathSeg &seg0, const SplashXPathSeg &seg1) {
SplashCoord x0, y0, x1, y1;
- if (seg0->flags & splashXPathFlip) {
- x0 = seg0->x1;
- y0 = seg0->y1;
+ if (seg0.flags & splashXPathFlip) {
+ x0 = seg0.x1;
+ y0 = seg0.y1;
} else {
- x0 = seg0->x0;
- y0 = seg0->y0;
+ x0 = seg0.x0;
+ y0 = seg0.y0;
}
- if (seg1->flags & splashXPathFlip) {
- x1 = seg1->x1;
- y1 = seg1->y1;
+ if (seg1.flags & splashXPathFlip) {
+ x1 = seg1.x1;
+ y1 = seg1.y1;
} else {
- x1 = seg1->x0;
- y1 = seg1->y0;
+ x1 = seg1.x0;
+ y1 = seg1.y0;
}
if (y0 != y1) {
- return (y0 > y1) ? 1 : -1;
+ return (y0 < y1) ? true : false;
}
if (x0 != x1) {
- return (x0 > x1) ? 1 : -1;
+ return (x0 < x1) ? true : false;
}
- return 0;
+ return false;
}
void SplashXPath::aaScale() {
@@ -439,5 +453,5 @@ void SplashXPath::aaScale() {
}
void SplashXPath::sort() {
- qsort(segs, length, sizeof(SplashXPathSeg), &cmpXPathSegs);
+ std::sort(segs, segs + length, &cmpXPathSegs);
}
diff --git a/splash/SplashXPathScanner.cc b/splash/SplashXPathScanner.cc
index eab9cef..33aa392 100644
--- a/splash/SplashXPathScanner.cc
+++ b/splash/SplashXPathScanner.cc
@@ -11,7 +11,8 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
-// Copyright (C) 2008 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008, 2010 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2010 PaweÅ Wiejacha <pawel.wiejacha at gmail.com>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -26,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
+#include <algorithm>
#include "goo/gmem.h"
#include "SplashMath.h"
#include "SplashXPath.h"
@@ -39,8 +41,8 @@ struct SplashIntersect {
int count; // EO/NZWN counter increment
};
-static int cmpIntersect(const void *p0, const void *p1) {
- return ((SplashIntersect *)p0)->x0 - ((SplashIntersect *)p1)->x0;
+static bool cmpIntersect(const SplashIntersect &p0, const SplashIntersect &p1) {
+ return p0.x0 < p1.x0;
}
//------------------------------------------------------------------------
@@ -301,7 +303,7 @@ void SplashXPathScanner::computeIntersections(int y) {
++interLen;
}
- qsort(inter, interLen, sizeof(SplashIntersect), &cmpIntersect);
+ std::sort(inter, inter + interLen, cmpIntersect);
interY = y;
interIdx = 0;
More information about the poppler
mailing list