QDir: replace a QScopedArrayPointer with a QVLA

QDirSortItem contains three implicitly-shared members (two QStrings
and one QFileInfo), so the mere default-initialization of the
QDirSortItem[n] array with which we initialize the QScopedArrayPointer
will take quite some time.

Using QVarLengthArray, OTOH, delays construction until we have the
data to initialize the sort items, saving n default constructor and n
move assignment operator calls, plus the memory allocation for the
case where we have less than 65 elements to sort.

This code precedes the start of the public history, but the
emplacement won't work before 905bc6293354a0d3ee832b6dd3f632a647f809f3
introduced the QDirSortItem ctor, so not picking back further than
that.

Change-Id: I262217eabaded2a6aef08b87fc6369812bc8958a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 81a0753299fb8cc3e6b4b5e41a0292024ccea9e5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-05-14 07:23:38 +02:00 committed by Qt Cherry-pick Bot
parent 61a593a469
commit f7847ccd22

View File

@ -313,9 +313,10 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, const QFileInfoList
names->append(fi.fileName());
}
} else {
QScopedArrayPointer<QDirSortItem> si(new QDirSortItem[n]);
QVarLengthArray<QDirSortItem, 64> si;
si.reserve(n);
for (qsizetype i = 0; i < n; ++i)
si[i] = QDirSortItem{l.at(i), sort};
si.emplace_back(l.at(i), sort);
#ifndef QT_BOOTSTRAPPED
if (sort.testAnyFlag(QDir::LocaleAware)) {