summaryrefslogtreecommitdiffstats
path: root/src/plugins/gfxdrivers
diff options
context:
space:
mode:
authorJames Perrett <james.perrett@tandberg.com>2010-07-08 13:06:15 (GMT)
committerJørgen Lind <jorgen.lind@nokia.com>2010-07-08 13:06:15 (GMT)
commit0bad059e4120b6e6c25427a19e3da942c1ff3151 (patch)
treee9eb8960a73473def5a246705c1d58a1b2db6e13 /src/plugins/gfxdrivers
parent9b0ab2254f09d7c465e7f92cb2a41eddce83a84b (diff)
downloadQt-0bad059e4120b6e6c25427a19e3da942c1ff3151.zip
Qt-0bad059e4120b6e6c25427a19e3da942c1ff3151.tar.gz
Qt-0bad059e4120b6e6c25427a19e3da942c1ff3151.tar.bz2
Avoid static local QHash
Change formatDictionary() to return a QHash by-value rather than a const reference to a static local QHash. This avoids memory being permanently allocated on the heap for a dictionary that is only needed during startup. Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Diffstat (limited to 'src/plugins/gfxdrivers')
-rw-r--r--src/plugins/gfxdrivers/eglnullws/eglnullwsscreen.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/plugins/gfxdrivers/eglnullws/eglnullwsscreen.cpp b/src/plugins/gfxdrivers/eglnullws/eglnullwsscreen.cpp
index 341caff..4213097 100644
--- a/src/plugins/gfxdrivers/eglnullws/eglnullwsscreen.cpp
+++ b/src/plugins/gfxdrivers/eglnullws/eglnullwsscreen.cpp
@@ -25,18 +25,16 @@ bool EGLNullWSScreen::initDevice()
return true;
}
-static const QHash<QString, QImage::Format> & formatDictionary()
+static const QHash<QString, QImage::Format> formatDictionary()
{
- static QHash<QString, QImage::Format> dictionary;
- if (dictionary.isEmpty()) {
- dictionary["rgb32"] = QImage::Format_RGB32;
- dictionary["argb32"] = QImage::Format_ARGB32;
- dictionary["rgb16"] = QImage::Format_RGB16;
- dictionary["rgb666"] = QImage::Format_RGB666;
- dictionary["rgb555"] = QImage::Format_RGB555;
- dictionary["rgb888"] = QImage::Format_RGB888;
- dictionary["rgb444"] = QImage::Format_RGB444;
- }
+ QHash<QString, QImage::Format> dictionary;
+ dictionary["rgb32"] = QImage::Format_RGB32;
+ dictionary["argb32"] = QImage::Format_ARGB32;
+ dictionary["rgb16"] = QImage::Format_RGB16;
+ dictionary["rgb666"] = QImage::Format_RGB666;
+ dictionary["rgb555"] = QImage::Format_RGB555;
+ dictionary["rgb888"] = QImage::Format_RGB888;
+ dictionary["rgb444"] = QImage::Format_RGB444;
return dictionary;
}
@@ -56,10 +54,10 @@ static int depthForFormat(QImage::Format format)
}
}
-static void printHelp()
+static void printHelp(const QHash<QString, QImage::Format> &formatDictionary)
{
QByteArray formatsBuf;
- QTextStream(&formatsBuf) << QStringList(formatDictionary().keys()).join(", ");
+ QTextStream(&formatsBuf) << QStringList(formatDictionary.keys()).join(", ");
qWarning(
"%s: Valid options are:\n"
"size=WIDTHxHEIGHT Screen size reported by this driver\n"
@@ -72,6 +70,7 @@ static void printHelp()
bool EGLNullWSScreen::connect(const QString &displaySpec)
{
const QStringList args = displaySpec.section(':', 1).split(':', QString::SkipEmptyParts);
+ const QHash<QString, QImage::Format> formatDict = formatDictionary();
Q_FOREACH(const QString arg, args) {
const QString optionName = arg.section('=', 0, 0);
const QString optionArg = arg.section('=', 1);
@@ -79,12 +78,12 @@ bool EGLNullWSScreen::connect(const QString &displaySpec)
w = optionArg.section('x', 0, 0).toInt();
h = optionArg.section('x', 1, 1).toInt();
} else if (optionName == QLatin1String("format")) {
- if (formatDictionary().contains(optionArg))
- setPixelFormat(formatDictionary().value(optionArg));
+ if (formatDict.contains(optionArg))
+ setPixelFormat(formatDict.value(optionArg));
else
- printHelp();
+ printHelp(formatDict);
} else {
- printHelp();
+ printHelp(formatDict);
}
}