From 1d8030cc64df2cdfdc0faf3d06ea7d9ed0306948 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 30 Dec 2015 02:04:26 +0100 Subject: QtWidgets: prevent detach attempts from first()/etc. use [dialogs, kernel, util, widgets] The algorithm used was: - If possible, just declare the container const - Otherwise, for first()/last(), use constFirst()/constLast() and for front()/back(), to not destroy the use of the STL API subset, use qAsConst() Did some caching of function returns here and there, and converted one 0 to nullptr as a drive-by. Also saves almost 4KiB in text size on optimized GCC 4.9 Linux AMD64 builds. Change-Id: I04b7bfd68dc85c22de247cb65a310e1cbbca1e8c Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll Reviewed-by: Marc Mutz --- src/widgets/dialogs/qfiledialog.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/widgets/dialogs/qfiledialog.cpp') diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 50667e2a91..c4ed72edc3 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -2689,7 +2689,7 @@ void QFileDialogPrivate::saveSettings() settings.beginGroup(QLatin1String("FileDialog")); if (usingWidgets()) { - settings.setValue(QLatin1String("sidebarWidth"), qFileDialogUi->splitter->sizes().first()); + settings.setValue(QLatin1String("sidebarWidth"), qFileDialogUi->splitter->sizes().constFirst()); settings.setValue(QLatin1String("shortcuts"), QUrl::toStringList(qFileDialogUi->sidebar->urls())); settings.setValue(QLatin1String("treeViewHeader"), qFileDialogUi->treeView->header()->saveState()); } @@ -3001,9 +3001,9 @@ void QFileDialogPrivate::createWidgets() q->selectNameFilter(options->initiallySelectedNameFilter()); q->setDefaultSuffix(options->defaultSuffix()); q->setHistory(options->history()); - if (options->initiallySelectedFiles().count() == 1) - q->selectFile(options->initiallySelectedFiles().first().fileName()); const auto initiallySelectedFiles = options->initiallySelectedFiles(); + if (initiallySelectedFiles.size() == 1) + q->selectFile(initiallySelectedFiles.first().fileName()); for (const QUrl &url : initiallySelectedFiles) q->selectUrl(url); lineEdit()->selectAll(); @@ -4095,7 +4095,7 @@ QStringList QFSCompleter::splitPath(const QString &path) const parts.removeFirst(); currentLocationList.removeLast(); } - if (!currentLocationList.isEmpty() && currentLocationList.last().isEmpty()) + if (!currentLocationList.isEmpty() && currentLocationList.constLast().isEmpty()) currentLocationList.removeLast(); return currentLocationList + parts; } -- cgit v1.2.3