From 4046ec71c86f41eb45d706ab3fc2bcf21fd59d9f Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 2 May 2012 23:19:13 +0200 Subject: [PATCH] QMimeType performance fix: don't reload from XML files over and over. Change-Id: Ie19c338ed6449ea1509306cbda5dc251295783ae Reviewed-by: Konstantin Ritt Reviewed-by: Thiago Macieira Reviewed-by: Stephen Kelly --- src/corelib/mimetypes/qmimeprovider.cpp | 3 +++ src/corelib/mimetypes/qmimetype.cpp | 5 ++++- src/corelib/mimetypes/qmimetype_p.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index 0c2f25a1f9..1f7d06caa4 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -529,6 +529,9 @@ QList QMimeBinaryProvider::allMimeTypes() void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data) { + if (data.loaded) + return; + data.loaded = true; // load comment and globPatterns const QString file = data.name + QLatin1String(".xml"); diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp index 5ee70e83b1..3a3112f4fd 100644 --- a/src/corelib/mimetypes/qmimetype.cpp +++ b/src/corelib/mimetypes/qmimetype.cpp @@ -63,6 +63,7 @@ bool qt_isQMimeTypeDebuggingActivated (false); #endif QMimeTypePrivate::QMimeTypePrivate() + : loaded(false) {} QMimeTypePrivate::QMimeTypePrivate(const QMimeType &other) @@ -70,7 +71,8 @@ QMimeTypePrivate::QMimeTypePrivate(const QMimeType &other) localeComments(other.d->localeComments), genericIconName(other.d->genericIconName), iconName(other.d->iconName), - globPatterns(other.d->globPatterns) + globPatterns(other.d->globPatterns), + loaded(other.d->loaded) {} void QMimeTypePrivate::clear() @@ -80,6 +82,7 @@ void QMimeTypePrivate::clear() genericIconName.clear(); iconName.clear(); globPatterns.clear(); + loaded = false; } /*! diff --git a/src/corelib/mimetypes/qmimetype_p.h b/src/corelib/mimetypes/qmimetype_p.h index f2c7f966ff..775d5278e2 100644 --- a/src/corelib/mimetypes/qmimetype_p.h +++ b/src/corelib/mimetypes/qmimetype_p.h @@ -68,6 +68,7 @@ public: QString genericIconName; QString iconName; QStringList globPatterns; + bool loaded; }; QT_END_NAMESPACE