summaryrefslogtreecommitdiffstats
path: root/src/gui/image
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2011-01-11 13:12:01 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2011-01-11 13:12:01 (GMT)
commitb500b9f35fbeaa5f0fe8bfaf7b225518bf6e636f (patch)
treeddc7bc7e013343374c8ec3ee8260821c95624c22 /src/gui/image
parent540fbb2aec0e9187acd75598a050edf8929e1d68 (diff)
downloadQt-b500b9f35fbeaa5f0fe8bfaf7b225518bf6e636f.zip
Qt-b500b9f35fbeaa5f0fe8bfaf7b225518bf6e636f.tar.gz
Qt-b500b9f35fbeaa5f0fe8bfaf7b225518bf6e636f.tar.bz2
use qBinaryFind instead of bsearch
depending on platform, qBinaryFind might be up to 3 times faster than bsearch or a bit bit slower at the worst case; so why don't simply use qBinaryFind instead of bsearch and be an optimist? ;) also we know that all color names are in the lower case already and thus we can avoid lowercasing of them again and again, and again; the name to find needs to be lowercased separately instead. some color-by-name-lookup numbers: before: 0.000737 msecs per iteration (total: 3,684, iterations: 5000000) after: 0.000154 msecs per iteration (total: 771, iterations: 5000000) Merge-request: 906 Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Diffstat (limited to 'src/gui/image')
-rw-r--r--src/gui/image/qxpmhandler.cpp32
1 files changed, 7 insertions, 25 deletions
diff --git a/src/gui/image/qxpmhandler.cpp b/src/gui/image/qxpmhandler.cpp
index 453100c..6afb305 100644
--- a/src/gui/image/qxpmhandler.cpp
+++ b/src/gui/image/qxpmhandler.cpp
@@ -54,12 +54,6 @@
#include "qplatformdefs.h"
#endif
-#include <stdlib.h>
-
-#if defined(Q_OS_WINCE)
-#include "qguifunctions_wince.h"
-#endif
-
QT_BEGIN_NAMESPACE
static quint64 xpmHash(const QString &str)
@@ -751,27 +745,15 @@ static const struct XPMRGBData {
{ QRGB(139,139, 0), "yellow4" },
{ QRGB(154,205, 50), "yellowgreen" } };
-#if defined(Q_C_CALLBACKS)
-extern "C" {
-#endif
-static int rgb_cmp(const void *d1, const void *d2)
-{
- return qstricmp(((XPMRGBData *)d1)->name, ((XPMRGBData *)d2)->name);
-}
-#if defined(Q_C_CALLBACKS)
-}
-#endif
+inline bool operator<(const char *name, const XPMRGBData &data)
+{ return qstrcmp(name, data.name) < 0; }
+inline bool operator<(const XPMRGBData &data, const char *name)
+{ return qstrcmp(data.name, name) < 0; }
-static bool qt_get_named_xpm_rgb(const char *name_no_space, QRgb *rgb)
+static inline bool qt_get_named_xpm_rgb(const char *name_no_space, QRgb *rgb)
{
- XPMRGBData x;
- x.name = name_no_space;
- // Function bsearch() is supposed to be
- // void *bsearch(const void *key, const void *base, ...
- // So why (char*)? Are there broken bsearch() declarations out there?
- XPMRGBData *r = (XPMRGBData *)bsearch((char *)&x, (char *)xpmRgbTbl, xpmRgbTblSize,
- sizeof(XPMRGBData), rgb_cmp);
- if (r) {
+ const XPMRGBData *r = qBinaryFind(xpmRgbTbl, xpmRgbTbl + xpmRgbTblSize, name_no_space);
+ if (r != xpmRgbTbl + xpmRgbTblSize) {
*rgb = r->value;
return true;
} else {