From 0bad059e4120b6e6c25427a19e3da942c1ff3151 Mon Sep 17 00:00:00 2001 From: James Perrett Date: Thu, 8 Jul 2010 15:06:15 +0200 Subject: Avoid static local QHash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../gfxdrivers/eglnullws/eglnullwsscreen.cpp | 33 +++++++++++----------- 1 file 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 & formatDictionary() +static const QHash formatDictionary() { - static QHash 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 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 &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 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); } } -- cgit v0.12