diff options
author | Peter Penz <ppenz@openismus.com> | 2010-07-07 10:59:21 +0200 |
---|---|---|
committer | Jörgen Scheibengruber <jorgen.scheibengruber@nokia.com> | 2010-07-07 14:50:13 +0300 |
commit | 68b736ca9ea1f5ccd9354f1efcdfa05469a256eb (patch) | |
tree | 0f8f1e0eea802c7c2166e85285134766fdce0300 /src/corelib/theme/mthemedaemon.cpp | |
parent | b367406ec0da16141c1ef68ad72712fae67f2e21 (diff) |
Changes: Reuse MThemeImagesDirectory instances if possible to speedup the performance
RevBy: Armin Berres
Details: When changing the theme, creating MThemeImageDirectory instances is quite expensive and can take up to around 1 second per instance. Reusing existing instances, like e. g. the base theme directory, improves the performance.
Diffstat (limited to 'src/corelib/theme/mthemedaemon.cpp')
-rw-r--r-- | src/corelib/theme/mthemedaemon.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/corelib/theme/mthemedaemon.cpp b/src/corelib/theme/mthemedaemon.cpp index 7e16e93d..238add71 100644 --- a/src/corelib/theme/mthemedaemon.cpp +++ b/src/corelib/theme/mthemedaemon.cpp @@ -182,12 +182,31 @@ ImageResource *MThemeDaemon::findImageResource(const QString &imageId) void MThemeDaemon::reloadImagePaths(const QString &locale) { - qDeleteAll(themeImageDirs); - themeImageDirs.clear(); - + QList<MThemeImagesDirectory*> newThemeImageDirs; foreach(const QString & theme, themeInheritance) { - themeImageDirs.append(new MThemeImagesDirectory(theme + "meegotouch", locale)); + const QString path = theme + "meegotouch"; + + // Creating a MThemeImagesDirectory is an expensive operation. + // Check whether there is already a MThemeImagesDirectory instance + // that can be reused. + bool foundDir = false; + for (int i = 0; i < themeImageDirs.size(); ++i) { + foundDir = (themeImageDirs[i]->path() == path) && (themeImageDirs[i]->locale() == locale); + if (foundDir) { + newThemeImageDirs.append(themeImageDirs[i]); + themeImageDirs[i] = 0; + break; + } + } + + if (!foundDir) { + // No existing MThemeImagesDirectory could be reused, create a new one + newThemeImageDirs.append(new MThemeImagesDirectory(path, locale)); + } } + + qDeleteAll(themeImageDirs); + themeImageDirs = newThemeImageDirs; } |