pruneNestedDirtyStyleElements function
Implementation
@visibleForTesting
List<MapEntry<Element, bool>> pruneNestedDirtyStyleElements(
Iterable<MapEntry<Element, bool>> dirtyElements) {
final List<MapEntry<Element, bool>> dirtyList = dirtyElements.toList();
if (dirtyList.length <= 1) {
return dirtyList;
}
final Set<int> rebuildNestedAddresses = <int>{};
for (final dirty in dirtyList) {
if (!dirty.value) {
continue;
}
final Pointer? pointer = dirty.key.pointer;
if (pointer != null) {
rebuildNestedAddresses.add(pointer.address);
}
}
if (rebuildNestedAddresses.isEmpty) {
return dirtyList;
}
final List<MapEntry<Element, bool>> effectiveDirty =
<MapEntry<Element, bool>>[];
for (final dirty in dirtyList) {
bool coveredByAncestorSubtreeRecalc = false;
Element? ancestor = dirty.key.parentElement;
while (ancestor != null) {
final Pointer? ancestorPtr = ancestor.pointer;
if (ancestorPtr != null &&
rebuildNestedAddresses.contains(ancestorPtr.address)) {
coveredByAncestorSubtreeRecalc = true;
break;
}
ancestor = ancestor.parentElement;
}
if (!coveredByAncestorSubtreeRecalc) {
effectiveDirty.add(dirty);
}
}
return effectiveDirty;
}