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 <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2022-10-06 19:10:33 +02:00
parent 605829546f
commit 2fc50a914d

View File

@ -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;
}