diff --git a/src/corelib/io/qdirlisting.cpp b/src/corelib/io/qdirlisting.cpp index 075672e39b9..6b9741a472b 100644 --- a/src/corelib/io/qdirlisting.cpp +++ b/src/corelib/io/qdirlisting.cpp @@ -723,14 +723,23 @@ QDirListing::const_iterator QDirListing::begin() const */ /*! + \fn QDirListing::const_iterator::operator++() + Advances the iterator and returns a reference to it. */ -QDirListing::const_iterator &QDirListing::const_iterator::operator++() + +/*! + \internal + + Implements the actual advancing. Not a member function to avoid forcing + DirEntry objects (and therefore const_iterator ones) onto the stack. +*/ +auto QDirListing::next(DirEntry dirEntry) -> DirEntry { dirEntry.dirListPtr->advance(); if (!dirEntry.dirListPtr->hasIterators()) - *this = {}; // All done, make `this` equal to the end() iterator - return *this; + return {}; // All done, make `this` equal to the end() iterator + return dirEntry; } /*! diff --git a/src/corelib/io/qdirlisting.h b/src/corelib/io/qdirlisting.h index 2a460676d28..74487f83bd3 100644 --- a/src/corelib/io/qdirlisting.h +++ b/src/corelib/io/qdirlisting.h @@ -119,7 +119,7 @@ public: reference operator*() const { return dirEntry; } pointer operator->() const { return &dirEntry; } - Q_CORE_EXPORT const_iterator &operator++(); + const_iterator &operator++() { dirEntry = next(dirEntry); return *this; } void operator++(int) { ++*this; }; // [iterator.concept.winc]/14 not required to return sth private: bool atEnd() const noexcept { return dirEntry.dirListPtr == nullptr; } @@ -146,6 +146,8 @@ public: private: Q_DISABLE_COPY(QDirListing) + Q_CORE_EXPORT static DirEntry next(DirEntry); + // Private constructor that is used in deprecated code paths. // `uint` instead of QDir::Filters and QDirIterator::IteratorFlags // because qdir.h can't be included here; qdiriterator.h can't included