diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2013-10-06 22:50:12 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-01-17 13:23:15 +0000 |
commit | 89f9f7cbdfd085c3536304ae52b8935096db7217 (patch) | |
tree | dfa5c0cdcb8ac253ef0d573b20bd7e539d3bdb7a /src | |
parent | d569f37dfd4ca9b2b704e13b95fab96abe0b0f97 (diff) |
QFileSystemModel: replace inefficient QList<Fetching> with QVector
The type Fetching is larger than a void*, so holding it in QList
is needlessly inefficient. Worse, the code could come to depend
on the fragile property of (inefficient) QLists that references
to elements therein never are invalidated.
Fix by holding it in QVector instead.
Also optimize the append site by liberal use of std::move(). This
code would greatly benefit from emplace_back(), but we can neither
assume it's present in std::vector nor do we require the necessary
C++11 features that would allow us to implement it in QVector, yet
(uniform init and, less so, variadic templates).
Change-Id: I50da0ffd557adff57477245d0e8c1fc1fec1ebc1
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/dialogs/qfilesystemmodel.cpp | 7 | ||||
-rw-r--r-- | src/widgets/dialogs/qfilesystemmodel_p.h | 2 |
2 files changed, 3 insertions, 6 deletions
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index e6ab64a112..bfa40317eb 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -472,11 +472,8 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS p->bypassFilters[node] = 1; QString dir = q->filePath(this->index(parent)); if (!node->hasInformation() && fetch) { - Fetching f; - f.dir = dir; - f.file = element; - f.node = node; - p->toFetch.append(f); + Fetching f = { std::move(dir), std::move(element), node }; + p->toFetch.append(std::move(f)); p->fetchingTimer.start(0, const_cast<QFileSystemModel*>(q)); } } diff --git a/src/widgets/dialogs/qfilesystemmodel_p.h b/src/widgets/dialogs/qfilesystemmodel_p.h index dc4dd26913..8e622e777a 100644 --- a/src/widgets/dialogs/qfilesystemmodel_p.h +++ b/src/widgets/dialogs/qfilesystemmodel_p.h @@ -324,7 +324,7 @@ public: QString file; const QFileSystemNode *node; }; - QList<Fetching> toFetch; + QVector<Fetching> toFetch; }; Q_DECLARE_TYPEINFO(QFileSystemModelPrivate::Fetching, Q_MOVABLE_TYPE); |