From 8726b6a35a7458e33a8dba922ebe659f25694e8d Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sat, 20 May 2023 04:18:49 +0300 Subject: [PATCH] Moc: use QList::removeIf Yes, the code now uses two loops, but it's slightly better than erasing-during-iteration; the alternative is using e.g. a while loop and advancing an iterator manually with operator++() (in two separate locations, since there would be a `continue` statement) or with the return value of QList::erase (in one location). Change-Id: I119d0e61bc06396f2158ecf9f4ae84a76d9bce7b Reviewed-by: Fabian Kosmale --- src/tools/moc/moc.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index b6671f6e12..ee15427e1c 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -1923,8 +1923,7 @@ void Moc::checkProperties(ClassDef *cdef) // returning pointers, or const char * for QByteArray. // QDuplicateTracker definedProperties(cdef->propertyList.size()); - for (int i = 0; i < cdef->propertyList.size(); ++i) { - PropertyDef &p = cdef->propertyList[i]; + auto hasNoAttributes = [&](const PropertyDef &p) { if (definedProperties.hasSeen(p.name)) { QByteArray msg = "The property '" + p.name + "' is defined multiple times in class " + cdef->classname + "."; warning(msg.constData()); @@ -1935,13 +1934,14 @@ void Moc::checkProperties(ClassDef *cdef) ", nor a READ accessor function nor an associated MEMBER variable. The property will be invalid."; const auto &sym = p.location >= 0 ? symbolAt(p.location) : Symbol(); warning(sym, msg.constData()); - if (p.write.isEmpty()) { - cdef->propertyList.removeAt(i); - --i; - } - continue; + if (p.write.isEmpty()) + return true; } + return false; + }; + cdef->propertyList.removeIf(hasNoAttributes); + for (PropertyDef &p : cdef->propertyList) { for (const FunctionDef &f : std::as_const(cdef->publicList)) { if (f.name != p.read) continue;