aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-04-23 22:39:42 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-04-26 13:31:01 +0000
commit1780a817fce77f4875f001c2b95b41cd2cd06f2b (patch)
tree094393e6df2f93f678be0863e26c7e3fac0557d9
parent1c90f5386d95acbef11b70869897c487f4fe0e6e (diff)
Optimize QQuickStyleSelector
QQuickStyle::name() accesses a Q_GLOBAL_STATIC and splits the style path. Don't call it repeatedly, but store the value in constructor to share it for all consequent select() calls. QQuickStyleSelector is allocated on the stack in QtQuickControls2Plugin::registerTypes(), so memory usage is no concern. Change-Id: I31c1693bca277911232e3cbd7cb6f55b2aa7ed2a Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/quickcontrols2/qquickstyleselector.cpp17
-rw-r--r--src/quickcontrols2/qquickstyleselector_p_p.h1
2 files changed, 9 insertions, 9 deletions
diff --git a/src/quickcontrols2/qquickstyleselector.cpp b/src/quickcontrols2/qquickstyleselector.cpp
index 93249192..5210a684 100644
--- a/src/quickcontrols2/qquickstyleselector.cpp
+++ b/src/quickcontrols2/qquickstyleselector.cpp
@@ -56,16 +56,13 @@ static bool isLocalScheme(const QString &scheme)
return local;
}
-static QStringList allSelectors(bool includeStyle)
+static QStringList allSelectors(const QString &style = QString())
{
static const QStringList platformSelectors = QFileSelectorPrivate::platformSelectors();
QStringList selectors = platformSelectors;
selectors += QLocale().name();
- if (includeStyle) {
- QString style = QQuickStyle::name();
- if (!style.isEmpty())
- selectors.prepend(style);
- }
+ if (!style.isEmpty())
+ selectors.prepend(style);
return selectors;
}
@@ -105,7 +102,7 @@ QString QQuickStyleSelectorPrivate::select(const QString &filePath) const
const QString path = fi.path();
const QString ret = selectionHelper(path.isEmpty() ? QString() : path + QLatin1Char('/'),
- fi.fileName(), allSelectors(true));
+ fi.fileName(), allSelectors(style));
if (!ret.isEmpty())
return ret;
@@ -114,6 +111,8 @@ QString QQuickStyleSelectorPrivate::select(const QString &filePath) const
QQuickStyleSelector::QQuickStyleSelector() : d_ptr(new QQuickStyleSelectorPrivate)
{
+ Q_D(QQuickStyleSelector);
+ d->style = QQuickStyle::name();
}
QQuickStyleSelector::~QQuickStyleSelector()
@@ -137,11 +136,11 @@ QString QQuickStyleSelector::select(const QString &fileName) const
Q_D(const QQuickStyleSelector);
const QString overridePath = QQuickStyle::path();
if (!overridePath.isEmpty()) {
- const QString stylePath = overridePath + QQuickStyle::name() + QLatin1Char('/');
+ const QString stylePath = overridePath + d->style + QLatin1Char('/');
if (QFile::exists(stylePath + fileName)) {
// the style name is included to the path, so exclude it from the selectors.
// the rest of the selectors (os, locale) are still valid, though.
- const QString selectedPath = selectionHelper(stylePath, fileName, allSelectors(false));
+ const QString selectedPath = selectionHelper(stylePath, fileName, allSelectors());
if (selectedPath.startsWith(QLatin1Char(':')))
return QLatin1String("qrc") + selectedPath;
return QUrl::fromLocalFile(QFileInfo(selectedPath).absoluteFilePath()).toString();
diff --git a/src/quickcontrols2/qquickstyleselector_p_p.h b/src/quickcontrols2/qquickstyleselector_p_p.h
index 0b37b13e..cc3f0a58 100644
--- a/src/quickcontrols2/qquickstyleselector_p_p.h
+++ b/src/quickcontrols2/qquickstyleselector_p_p.h
@@ -56,6 +56,7 @@ public:
QString select(const QString &filePath) const;
QUrl baseUrl;
+ QString style;
};
QT_END_NAMESPACE