From ad446d56897549b2cddb7b42ce7cbd6641a3c59b Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Wed, 6 Mar 2024 15:48:07 +0200 Subject: [PATCH] FileIteratorWrapper: refactor setPath() Only call setPath() in hasNext(), the latter is called before any other member method, and setPath() is guarded by a bool to only run a single time. Split some code to a helper function, which will be reused when porting to new QAFEngine API. Change-Id: Ibda0ede18593a3a20729b31e03e994ad2de126de Reviewed-by: Marcus Tillmanns --- .../fsengine/fileiteratordevicesappender.h | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libs/utils/fsengine/fileiteratordevicesappender.h b/src/libs/utils/fsengine/fileiteratordevicesappender.h index 77864117f46..0ce327690f2 100644 --- a/src/libs/utils/fsengine/fileiteratordevicesappender.h +++ b/src/libs/utils/fsengine/fileiteratordevicesappender.h @@ -47,7 +47,6 @@ public: if (m_status == State::Ended) return QString(); - setPath(); checkStatus(); if (m_status == State::BaseIteratorEnd) { @@ -75,7 +74,6 @@ public: if (m_status == State::Ended) return FilePath::specialRootPath(); - setPath(); checkStatus(); return m_baseIterator->currentFileName(); } @@ -83,22 +81,26 @@ public: { if (m_status == State::Ended) return QFileInfo(FilePath::specialRootPath()); - setPath(); checkStatus(); return m_baseIterator->currentFileInfo(); } private: + QString setStatus() const + { + // path() can be "/somedir/.." so we need to clean it first. + // We only need QDir::cleanPath here, as the path is always + // a fs engine path and will not contain scheme:// etc. + QString p = QDir::cleanPath(path()); + if (p.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0) + m_status = State::IteratingRoot; + return p; + } + void setPath() const { if (!m_hasSetPath) { - // path() can be "/somedir/.." so we need to clean it first. - // We only need QDir::cleanPath here, as the path is always - // a fs engine path and will not contain scheme:// etc. - const QString p = QDir::cleanPath(path()); - if (p.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0) - m_status = State::IteratingRoot; - + const QString &p = setStatus(); ((*m_baseIterator).*get(QAFEITag()))(p); m_hasSetPath = true; }