summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
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/painting
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/painting')
-rw-r--r--src/gui/painting/qcolor_p.cpp36
1 files changed, 8 insertions, 28 deletions
diff --git a/src/gui/painting/qcolor_p.cpp b/src/gui/painting/qcolor_p.cpp
index b1adf9f..d66990d 100644
--- a/src/gui/painting/qcolor_p.cpp
+++ b/src/gui/painting/qcolor_p.cpp
@@ -49,9 +49,6 @@
#include "qrgb.h"
#include "qstringlist.h"
-#if defined(Q_WS_WINCE)
-#include "qguifunctions_wince.h"
-#endif
QT_BEGIN_NAMESPACE
static inline int h2i(char hex)
@@ -290,33 +287,16 @@ static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData);
#undef rgb
-QT_BEGIN_INCLUDE_NAMESPACE
-#include <stdlib.h>
-QT_END_INCLUDE_NAMESPACE
-
-#if defined(Q_C_CALLBACKS)
-extern "C" {
-#endif
-
-#ifdef Q_OS_WINCE
-static int __cdecl rgb_cmp(const void *d1, const void *d2)
-#else
-static int rgb_cmp(const void *d1, const void *d2)
-#endif
-{
- return qstricmp(((RGBData *)d1)->name, ((RGBData *)d2)->name);
-}
-
-#if defined(Q_C_CALLBACKS)
-}
-#endif
+inline bool operator<(const char *name, const RGBData &data)
+{ return qstrcmp(name, data.name) < 0; }
+inline bool operator<(const RGBData &data, const char *name)
+{ return qstrcmp(data.name, name) < 0; }
-static bool get_named_rgb(const char *name, QRgb *rgb)
+static bool get_named_rgb(const char *name_no_space, QRgb *rgb)
{
- RGBData x;
- x.name = name;
- RGBData *r = (RGBData*)bsearch(&x, rgbTbl, rgbTblSize, sizeof(RGBData), rgb_cmp);
- if (r) {
+ QByteArray name = QByteArray(name_no_space).toLower();
+ const RGBData *r = qBinaryFind(rgbTbl, rgbTbl + rgbTblSize, name.constData());
+ if (r != rgbTbl + rgbTblSize) {
*rgb = r->value;
return true;
}