summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-12-29 21:51:39 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-01-01 23:32:13 +0000
commitbe94e009ae5d89d97456f5d1389d2a017dd2e69e (patch)
tree179e13c32668bad6db0983a2a8cdb0d71f65b60a /tests
parent024a52d0d12aaceffd67d0a1423408fb1f377d11 (diff)
QFileDialog: optimize string handling in qt_tildeExpansion
- Instead of QString::split()-ing the path, just to inspect the first item in the list returned, simply find the location of the first separator and work with that. -> saves creating a QList, and its QString elements -> saves attempted detaches of that list when calling first() - When extracting the user name, don't do it in a QString, do it in a QStringRef. - When constructing the result, don't use QString::replace(), use QStringBuilder with a QStringRef into the original string. - Eradicate the out parameter, it is easily calculated from the return value. - Don't calculate userName on VXWORKS and INTEGRITY, where it is not used. Requires a different #ifdef sequence. Fixed preprocessor directives' indention as a drive-by. Costs 84b in text size on optimized GCC 4.9 Linux AMD64 builds. Change-Id: I61f1e8d558db7fb0c5c1170bdfd6f5ac1f1a9e62 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
index 2ab9ca330f..c9de1c54c0 100644
--- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
@@ -68,7 +68,7 @@
#include <unistd.h> // for pathconf() on OS X
#ifdef QT_BUILD_INTERNAL
QT_BEGIN_NAMESPACE
-extern Q_GUI_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded = 0);
+extern Q_GUI_EXPORT QString qt_tildeExpansion(const QString &path);
QT_END_NAMESPACE
#endif
#endif
@@ -1395,15 +1395,18 @@ void tst_QFiledialog::tildeExpansion_data()
QTest::addColumn<QString>("tildePath");
QTest::addColumn<QString>("expandedPath");
+ const QString tilde = QStringLiteral("~");
+ const QString tildeUser = tilde + QString(qgetenv("USER"));
+ const QLatin1String someSubDir("/some/sub/dir");
+ const QString homePath = QDir::homePath();
+ const QString invalid = QStringLiteral("~thisIsNotAValidUserName");
+
QTest::newRow("empty path") << QString() << QString();
- QTest::newRow("~") << QString::fromLatin1("~") << QDir::homePath();
- QTest::newRow("~/some/sub/dir/") << QString::fromLatin1("~/some/sub/dir") << QDir::homePath()
- + QString::fromLatin1("/some/sub/dir");
- QString userHome = QString(qgetenv("USER"));
- userHome.prepend('~');
- QTest::newRow("current user (~<user> syntax)") << userHome << QDir::homePath();
- QString invalid = QString::fromLatin1("~thisIsNotAValidUserName");
- QTest::newRow("invalid user name") << invalid << invalid;
+ QTest::newRow("~") << tilde << homePath;
+ QTest::newRow("~/some/sub/dir/") << tilde + someSubDir << homePath + someSubDir;
+ QTest::newRow("~<user>") << tildeUser << homePath;
+ QTest::newRow("~<user>/some/sub/dir") << tildeUser + someSubDir << homePath + someSubDir;
+ QTest::newRow("invalid user name") << invalid << invalid;
}
#endif // QT_BUILD_INTERNAL