From 2fc50a914d4b972e2c1b8f78f176c86ceece1111 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Thu, 6 Oct 2022 19:10:33 +0200 Subject: QDir: when sorting by time, get last modification times as UTC directly PASS : tst_QDir_10000::sorted_byTime() RESULT : tst_QDir_10000::sorted_byTime(): 345 msecs per iteration (total: 345, iterations: 1) PASS : tst_QDir_10000::sorted_byTime() RESULT : tst_QDir_10000::sorted_byTime(): 0.000015 msecs per iteration (total: 54, iterations: 262144) Change-Id: I7976c8668aa821d2b7ed3f774f29bdf1ba4a99d1 Reviewed-by: Thiago Macieira --- src/corelib/io/qdir.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 3e42ad0979..547512bf59 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -219,16 +219,8 @@ bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortIt switch (sortBy) { case QDir::Time: { - QDateTime firstModified = f1->item.lastModified(); - QDateTime secondModified = f2->item.lastModified(); - - // QDateTime by default will do all sorts of conversions on these to - // find timezones, which is incredibly expensive. As we aren't - // presenting these to the user, we don't care (at all) about the - // local timezone, so force them to UTC to avoid that conversion. - firstModified.setTimeZone(QTimeZone::UTC); - secondModified.setTimeZone(QTimeZone::UTC); - + const QDateTime firstModified = f1->item.lastModified(QTimeZone::UTC); + const QDateTime secondModified = f2->item.lastModified(QTimeZone::UTC); r = firstModified.msecsTo(secondModified); break; } -- cgit v1.2.3