QObject: de-pessimize installEventFilter()
Don't loop over the list of event filters twice, do it once with a combined predicate. This code is still has a big impedance mismatch: the removeIf() will always leave empty space at the back while prepend() needs it at the front. We should fix this by reversing the meaning of the order of event filters to mean back()-is-applied-first, so new filters can be append()ed, but that is for another patch. Done-with: Jarek Kobus <jaroslaw.kobus@qt.io> Pick-to: 6.7 Change-Id: I08324697229a54c8f66c6c320cf7232d707a08f1 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>bb10
parent
b909b8dfe8
commit
edff6a33a1
|
|
@ -2352,9 +2352,9 @@ void QObject::installEventFilter(QObject *obj)
|
|||
|
||||
d->ensureExtraData();
|
||||
|
||||
// clean up unused items in the list
|
||||
d->extraData->eventFilters.removeAll((QObject *)nullptr);
|
||||
d->extraData->eventFilters.removeAll(obj);
|
||||
// clean up unused items in the list along the way:
|
||||
auto isNullOrEquals = [](auto obj) { return [obj](const auto &p) { return !p || p == obj; }; };
|
||||
d->extraData->eventFilters.removeIf(isNullOrEquals(obj));
|
||||
d->extraData->eventFilters.prepend(obj);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue