diff options
author | Marc Mutz <marc.mutz@qt.io> | 2024-05-14 07:23:38 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2024-05-15 11:34:08 +0200 |
commit | 81a0753299fb8cc3e6b4b5e41a0292024ccea9e5 (patch) | |
tree | 5d8193973860d5fd116468f09c964c2981a2a312 | |
parent | 28b384898924fc2862c21876c73b1bcba52edd72 (diff) |
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.
Pick-to: 6.7
Change-Id: I262217eabaded2a6aef08b87fc6369812bc8958a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/io/qdir.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 9291201d88..05947f3380 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -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)) { |