diff options
author | Carlos Garcia Campos <carlosgc@gnome.org> | 2011-08-30 16:21:40 +0200 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2011-08-30 16:24:31 +0200 |
commit | 1df3489392a77e2b75adbafcc2fa10de829c172e (patch) | |
tree | 6b1e77af8bd4458a95bc9e0dc63ffa3098a04ca7 /splash/SplashScreen.cc | |
parent | f298e7f844105f2d9a36144e59be86c341e37507 (diff) |
xpdf303: Use std::sort (with functors) in place of qsort
It can be significantly faster. Not included changes in
SplashXPathScanner.cc since they depend on other changes not yet merged.
Diffstat (limited to 'splash/SplashScreen.cc')
-rw-r--r-- | splash/SplashScreen.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/splash/SplashScreen.cc b/splash/SplashScreen.cc index 6b75c0ca..40f24664 100644 --- a/splash/SplashScreen.cc +++ b/splash/SplashScreen.cc @@ -26,6 +26,7 @@ #include <stdlib.h> #include <string.h> +#include <algorithm> #include "goo/gmem.h" #include "SplashMath.h" #include "SplashScreen.h" @@ -46,9 +47,12 @@ struct SplashScreenPoint { int dist; }; -static int cmpDistances(const void *p0, const void *p1) { - return ((SplashScreenPoint *)p0)->dist - ((SplashScreenPoint *)p1)->dist; -} + +struct cmpDistancesFunctor { + bool operator()(const SplashScreenPoint &p0, const SplashScreenPoint &p1) { + return p0.dist < p1.dist; + } +}; //------------------------------------------------------------------------ // SplashScreen @@ -360,7 +364,7 @@ void SplashScreen::buildSCDMatrix(int r) { } } } - qsort(pts, n, sizeof(SplashScreenPoint), &cmpDistances); + std::sort(pts, pts + n, cmpDistancesFunctor()); for (j = 0; j < n; ++j) { // map values in [0 .. n-1] --> [255 .. 1] mat[pts[j].y * size + pts[j].x] = 255 - (254 * j) / (n - 1); |