summaryrefslogtreecommitdiffstats
path: root/src/tools/moc/moc.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-05-20 04:18:49 +0300
committerAhmad Samir <a.samirh78@gmail.com>2023-06-22 02:20:29 +0300
commit8726b6a35a7458e33a8dba922ebe659f25694e8d (patch)
tree26e92d1f9fb4576596d2e8b5f31f6cf961a7dcd8 /src/tools/moc/moc.cpp
parenta993510c9eb2da86a24a0c42ce13fbe3a9fa062b (diff)
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 <fabian.kosmale@qt.io>
Diffstat (limited to 'src/tools/moc/moc.cpp')
-rw-r--r--src/tools/moc/moc.cpp14
1 files 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<QByteArray> 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;