summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2013-09-04 09:10:39 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-08 21:16:03 +0200
commit115da758b9ea3195dfd35c672caee05e9cc90038 (patch)
tree1f555d36823c7d480096b5165c45b606600a8b3c /src/plugins/platforms
parent50e2db6a752b5d8b3af3023ff4cebb13ef2b9a2a (diff)
Replace XCB native interface resource map by a lookup function.
Remove global variable and duplicated lookup in the old code (map.contains() followed by map.value()). Change-Id: Id68c34bf38c6706db69dcb8422c3b1ea718aa064 Y# issue or contains a behavior change that is relevant to others, Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/xcb/qxcbnativeinterface.cpp66
1 files changed, 23 insertions, 43 deletions
diff --git a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
index 99e9932847..72299d5a9a 100644
--- a/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
+++ b/src/plugins/platforms/xcb/qxcbnativeinterface.cpp
@@ -66,30 +66,28 @@
# include <stdio.h>
#endif
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
-class QXcbResourceMap : public QMap<QByteArray, QXcbNativeInterface::ResourceType>
+// return QXcbNativeInterface::ResourceType for the key.
+static int resourceType(const QByteArray &key)
{
-public:
- QXcbResourceMap()
- :QMap<QByteArray, QXcbNativeInterface::ResourceType>()
- {
- insert("display",QXcbNativeInterface::Display);
- insert("egldisplay",QXcbNativeInterface::EglDisplay);
- insert("connection",QXcbNativeInterface::Connection);
- insert("screen",QXcbNativeInterface::Screen);
- insert("eglcontext",QXcbNativeInterface::EglContext);
- insert("glxcontext",QXcbNativeInterface::GLXContext);
- insert("apptime",QXcbNativeInterface::AppTime);
- insert("appusertime",QXcbNativeInterface::AppUserTime);
- insert("hintstyle", QXcbNativeInterface::ScreenHintStyle);
- insert("startupid", QXcbNativeInterface::StartupId);
- insert(QByteArrayLiteral("traywindow"), QXcbNativeInterface::TrayWindow);
- insert(QByteArrayLiteral("gettimestamp"), QXcbNativeInterface::GetTimestamp);
- }
-};
-
-Q_GLOBAL_STATIC(QXcbResourceMap, qXcbResourceMap)
+ static const QByteArray names[] = { // match QXcbNativeInterface::ResourceType
+ QByteArrayLiteral("display"), QByteArrayLiteral("egldisplay"),
+ QByteArrayLiteral("connection"), QByteArrayLiteral("screen"),
+ QByteArrayLiteral("graphicsdevice"), QByteArrayLiteral("eglcontext"),
+ QByteArrayLiteral("glxcontext"), QByteArrayLiteral("apptime"),
+ QByteArrayLiteral("appusertime"), QByteArrayLiteral("hintstyle"),
+ QByteArrayLiteral("startupid"), QByteArrayLiteral("traywindow"),
+ QByteArrayLiteral("gettimestamp")
+ };
+ const QByteArray *end = names + sizeof(names) / sizeof(names[0]);
+ const QByteArray *result = std::find(names, end, key);
+ if (result == end)
+ result = std::find(names, end, key.toLower());
+ return int(result - names);
+}
QXcbNativeInterface::QXcbNativeInterface() :
m_genericEventFilterType(QByteArrayLiteral("xcb_generic_event_t"))
@@ -136,13 +134,8 @@ QRect QXcbNativeInterface::systemTrayWindowGlobalGeometry(const QWindow *window)
void *QXcbNativeInterface::nativeResourceForIntegration(const QByteArray &resourceString)
{
- QByteArray lowerCaseResource = resourceString.toLower();
- if (!qXcbResourceMap()->contains(lowerCaseResource))
- return 0;
-
- ResourceType resource = qXcbResourceMap()->value(lowerCaseResource);
void *result = 0;
- switch (resource) {
+ switch (resourceType(resourceString)) {
case StartupId:
result = startupId();
break;
@@ -155,13 +148,8 @@ void *QXcbNativeInterface::nativeResourceForIntegration(const QByteArray &resour
void *QXcbNativeInterface::nativeResourceForContext(const QByteArray &resourceString, QOpenGLContext *context)
{
- QByteArray lowerCaseResource = resourceString.toLower();
- if (!qXcbResourceMap()->contains(lowerCaseResource))
- return 0;
-
- ResourceType resource = qXcbResourceMap()->value(lowerCaseResource);
void *result = 0;
- switch(resource) {
+ switch (resourceType(resourceString)) {
case EglContext:
result = eglContextForContext(context);
break;
@@ -177,12 +165,9 @@ void *QXcbNativeInterface::nativeResourceForContext(const QByteArray &resourceSt
void *QXcbNativeInterface::nativeResourceForScreen(const QByteArray &resource, QScreen *screen)
{
- const QXcbResourceMap::const_iterator it = qXcbResourceMap()->constFind(resource.toLower());
- if (it == qXcbResourceMap()->constEnd() || !screen->handle())
- return 0;
void *result = 0;
const QXcbScreen *xcbScreen = static_cast<QXcbScreen *>(screen->handle());
- switch (it.value()) {
+ switch (resourceType(resource)) {
case Display:
#ifdef XCB_USE_XLIB
result = xcbScreen->connection()->xlib_display();
@@ -212,13 +197,8 @@ void *QXcbNativeInterface::nativeResourceForScreen(const QByteArray &resource, Q
void *QXcbNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window)
{
- QByteArray lowerCaseResource = resourceString.toLower();
- if (!qXcbResourceMap()->contains(lowerCaseResource))
- return 0;
-
- ResourceType resource = qXcbResourceMap()->value(lowerCaseResource);
void *result = 0;
- switch(resource) {
+ switch (resourceType(resourceString)) {
case Display:
result = displayForWindow(window);
break;