Unverified Commit dae720be authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Remove remaining uses of `childToSlot` (#64273)

The remaining uses of this pattern were all due to wanting to have
the child's slot when `Element.forgetChild()` was called. However,
when that method is called, the child's `slot` value is still valid
in the context of the parent, so the uses can just use `child.slot`.

This is the final round of cleanup from the fallout of #63269
parent 90908b0b
...@@ -748,7 +748,6 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { ...@@ -748,7 +748,6 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
List<Element> _children; List<Element> _children;
final Map<_CupertinoTextSelectionToolbarItemsSlot, Element> slotToChild = <_CupertinoTextSelectionToolbarItemsSlot, Element>{}; final Map<_CupertinoTextSelectionToolbarItemsSlot, Element> slotToChild = <_CupertinoTextSelectionToolbarItemsSlot, Element>{};
final Map<Element, _CupertinoTextSelectionToolbarItemsSlot> childToSlot = <Element, _CupertinoTextSelectionToolbarItemsSlot>{};
// We keep a set of forgotten children to avoid O(n^2) work walking _children // We keep a set of forgotten children to avoid O(n^2) work walking _children
// repeatedly to remove children. // repeatedly to remove children.
...@@ -829,12 +828,11 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { ...@@ -829,12 +828,11 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
@override @override
void forgetChild(Element child) { void forgetChild(Element child) {
assert(slotToChild.values.contains(child) || _children.contains(child)); assert(slotToChild.containsValue(child) || _children.contains(child));
assert(!_forgottenChildren.contains(child)); assert(!_forgottenChildren.contains(child));
// Handle forgetting a child in children or in a slot. // Handle forgetting a child in children or in a slot.
if (childToSlot.containsKey(child)) { if (slotToChild.containsKey(child.slot)) {
final _CupertinoTextSelectionToolbarItemsSlot slot = childToSlot[child]; final _CupertinoTextSelectionToolbarItemsSlot slot = child.slot as _CupertinoTextSelectionToolbarItemsSlot;
childToSlot.remove(child);
slotToChild.remove(slot); slotToChild.remove(slot);
} else { } else {
_forgottenChildren.add(child); _forgottenChildren.add(child);
...@@ -848,11 +846,9 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { ...@@ -848,11 +846,9 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
final Element newChild = updateChild(oldChild, widget, slot); final Element newChild = updateChild(oldChild, widget, slot);
if (oldChild != null) { if (oldChild != null) {
slotToChild.remove(slot); slotToChild.remove(slot);
childToSlot.remove(oldChild);
} }
if (newChild != null) { if (newChild != null) {
slotToChild[slot] = newChild; slotToChild[slot] = newChild;
childToSlot[newChild] = slot;
} }
} }
...@@ -877,12 +873,11 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { ...@@ -877,12 +873,11 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
@override @override
void debugVisitOnstageChildren(ElementVisitor visitor) { void debugVisitOnstageChildren(ElementVisitor visitor) {
// Visit slot children. // Visit slot children.
childToSlot.forEach((Element child, _) { for (final Element child in slotToChild.values) {
if (!_shouldPaint(child) || _forgottenChildren.contains(child)) { if (_shouldPaint(child) && !_forgottenChildren.contains(child)) {
return; visitor(child);
} }
visitor(child); }
});
// Visit list children. // Visit list children.
_children _children
.where((Element child) => !_forgottenChildren.contains(child) && _shouldPaint(child)) .where((Element child) => !_forgottenChildren.contains(child) && _shouldPaint(child))
......
...@@ -2067,7 +2067,6 @@ class _RenderChipElement extends RenderObjectElement { ...@@ -2067,7 +2067,6 @@ class _RenderChipElement extends RenderObjectElement {
_RenderChipElement(_ChipRenderWidget chip) : super(chip); _RenderChipElement(_ChipRenderWidget chip) : super(chip);
final Map<_ChipSlot, Element> slotToChild = <_ChipSlot, Element>{}; final Map<_ChipSlot, Element> slotToChild = <_ChipSlot, Element>{};
final Map<Element, _ChipSlot> childToSlot = <Element, _ChipSlot>{};
@override @override
_ChipRenderWidget get widget => super.widget as _ChipRenderWidget; _ChipRenderWidget get widget => super.widget as _ChipRenderWidget;
...@@ -2082,11 +2081,10 @@ class _RenderChipElement extends RenderObjectElement { ...@@ -2082,11 +2081,10 @@ class _RenderChipElement extends RenderObjectElement {
@override @override
void forgetChild(Element child) { void forgetChild(Element child) {
assert(slotToChild.values.contains(child)); assert(slotToChild.containsValue(child));
assert(childToSlot.keys.contains(child)); assert(child.slot is _ChipSlot);
final _ChipSlot slot = childToSlot[child]; assert(slotToChild.containsKey(child.slot));
childToSlot.remove(child); slotToChild.remove(child.slot);
slotToChild.remove(slot);
super.forgetChild(child); super.forgetChild(child);
} }
...@@ -2095,11 +2093,9 @@ class _RenderChipElement extends RenderObjectElement { ...@@ -2095,11 +2093,9 @@ class _RenderChipElement extends RenderObjectElement {
final Element newChild = updateChild(oldChild, widget, slot); final Element newChild = updateChild(oldChild, widget, slot);
if (oldChild != null) { if (oldChild != null) {
slotToChild.remove(slot); slotToChild.remove(slot);
childToSlot.remove(oldChild);
} }
if (newChild != null) { if (newChild != null) {
slotToChild[slot] = newChild; slotToChild[slot] = newChild;
childToSlot[newChild] = slot;
} }
} }
...@@ -2115,12 +2111,10 @@ class _RenderChipElement extends RenderObjectElement { ...@@ -2115,12 +2111,10 @@ class _RenderChipElement extends RenderObjectElement {
final Element oldChild = slotToChild[slot]; final Element oldChild = slotToChild[slot];
final Element newChild = updateChild(oldChild, widget, slot); final Element newChild = updateChild(oldChild, widget, slot);
if (oldChild != null) { if (oldChild != null) {
childToSlot.remove(oldChild);
slotToChild.remove(slot); slotToChild.remove(slot);
} }
if (newChild != null) { if (newChild != null) {
slotToChild[slot] = newChild; slotToChild[slot] = newChild;
childToSlot[newChild] = slot;
} }
} }
......
...@@ -1526,11 +1526,10 @@ class _RenderDecoration extends RenderBox { ...@@ -1526,11 +1526,10 @@ class _RenderDecoration extends RenderBox {
} }
} }
class _RenderDecorationElement extends RenderObjectElement { class _DecorationElement extends RenderObjectElement {
_RenderDecorationElement(_Decorator widget) : super(widget); _DecorationElement(_Decorator widget) : super(widget);
final Map<_DecorationSlot, Element> slotToChild = <_DecorationSlot, Element>{}; final Map<_DecorationSlot, Element> slotToChild = <_DecorationSlot, Element>{};
final Map<Element, _DecorationSlot> childToSlot = <Element, _DecorationSlot>{};
@override @override
_Decorator get widget => super.widget as _Decorator; _Decorator get widget => super.widget as _Decorator;
...@@ -1545,11 +1544,10 @@ class _RenderDecorationElement extends RenderObjectElement { ...@@ -1545,11 +1544,10 @@ class _RenderDecorationElement extends RenderObjectElement {
@override @override
void forgetChild(Element child) { void forgetChild(Element child) {
assert(slotToChild.values.contains(child)); assert(slotToChild.containsValue(child));
assert(childToSlot.keys.contains(child)); assert(child.slot is _DecorationSlot);
final _DecorationSlot slot = childToSlot[child]; assert(slotToChild.containsKey(child.slot));
childToSlot.remove(child); slotToChild.remove(child.slot);
slotToChild.remove(slot);
super.forgetChild(child); super.forgetChild(child);
} }
...@@ -1558,11 +1556,9 @@ class _RenderDecorationElement extends RenderObjectElement { ...@@ -1558,11 +1556,9 @@ class _RenderDecorationElement extends RenderObjectElement {
final Element newChild = updateChild(oldChild, widget, slot); final Element newChild = updateChild(oldChild, widget, slot);
if (oldChild != null) { if (oldChild != null) {
slotToChild.remove(slot); slotToChild.remove(slot);
childToSlot.remove(oldChild);
} }
if (newChild != null) { if (newChild != null) {
slotToChild[slot] = newChild; slotToChild[slot] = newChild;
childToSlot[newChild] = slot;
} }
} }
...@@ -1586,12 +1582,10 @@ class _RenderDecorationElement extends RenderObjectElement { ...@@ -1586,12 +1582,10 @@ class _RenderDecorationElement extends RenderObjectElement {
final Element oldChild = slotToChild[slot]; final Element oldChild = slotToChild[slot];
final Element newChild = updateChild(oldChild, widget, slot); final Element newChild = updateChild(oldChild, widget, slot);
if (oldChild != null) { if (oldChild != null) {
childToSlot.remove(oldChild);
slotToChild.remove(slot); slotToChild.remove(slot);
} }
if (newChild != null) { if (newChild != null) {
slotToChild[slot] = newChild; slotToChild[slot] = newChild;
childToSlot[newChild] = slot;
} }
} }
...@@ -1694,7 +1688,7 @@ class _Decorator extends RenderObjectWidget { ...@@ -1694,7 +1688,7 @@ class _Decorator extends RenderObjectWidget {
final bool expands; final bool expands;
@override @override
_RenderDecorationElement createElement() => _RenderDecorationElement(this); _DecorationElement createElement() => _DecorationElement(this);
@override @override
_RenderDecoration createRenderObject(BuildContext context) { _RenderDecoration createRenderObject(BuildContext context) {
......
...@@ -1164,7 +1164,6 @@ class _ListTileElement extends RenderObjectElement { ...@@ -1164,7 +1164,6 @@ class _ListTileElement extends RenderObjectElement {
_ListTileElement(_ListTile widget) : super(widget); _ListTileElement(_ListTile widget) : super(widget);
final Map<_ListTileSlot, Element> slotToChild = <_ListTileSlot, Element>{}; final Map<_ListTileSlot, Element> slotToChild = <_ListTileSlot, Element>{};
final Map<Element, _ListTileSlot> childToSlot = <Element, _ListTileSlot>{};
@override @override
_ListTile get widget => super.widget as _ListTile; _ListTile get widget => super.widget as _ListTile;
...@@ -1179,11 +1178,10 @@ class _ListTileElement extends RenderObjectElement { ...@@ -1179,11 +1178,10 @@ class _ListTileElement extends RenderObjectElement {
@override @override
void forgetChild(Element child) { void forgetChild(Element child) {
assert(slotToChild.values.contains(child)); assert(slotToChild.containsValue(child));
assert(childToSlot.keys.contains(child)); assert(child.slot is _ListTileSlot);
final _ListTileSlot slot = childToSlot[child]; assert(slotToChild.containsKey(child.slot));
childToSlot.remove(child); slotToChild.remove(child.slot);
slotToChild.remove(slot);
super.forgetChild(child); super.forgetChild(child);
} }
...@@ -1192,11 +1190,9 @@ class _ListTileElement extends RenderObjectElement { ...@@ -1192,11 +1190,9 @@ class _ListTileElement extends RenderObjectElement {
final Element newChild = updateChild(oldChild, widget, slot); final Element newChild = updateChild(oldChild, widget, slot);
if (oldChild != null) { if (oldChild != null) {
slotToChild.remove(slot); slotToChild.remove(slot);
childToSlot.remove(oldChild);
} }
if (newChild != null) { if (newChild != null) {
slotToChild[slot] = newChild; slotToChild[slot] = newChild;
childToSlot[newChild] = slot;
} }
} }
...@@ -1213,12 +1209,10 @@ class _ListTileElement extends RenderObjectElement { ...@@ -1213,12 +1209,10 @@ class _ListTileElement extends RenderObjectElement {
final Element oldChild = slotToChild[slot]; final Element oldChild = slotToChild[slot];
final Element newChild = updateChild(oldChild, widget, slot); final Element newChild = updateChild(oldChild, widget, slot);
if (oldChild != null) { if (oldChild != null) {
childToSlot.remove(oldChild);
slotToChild.remove(slot); slotToChild.remove(slot);
} }
if (newChild != null) { if (newChild != null) {
slotToChild[slot] = newChild; slotToChild[slot] = newChild;
childToSlot[newChild] = slot;
} }
} }
......
...@@ -3561,8 +3561,10 @@ abstract class Element extends DiagnosticableTree implements BuildContext { ...@@ -3561,8 +3561,10 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
/// This updates the child model such that, e.g., [visitChildren] does not /// This updates the child model such that, e.g., [visitChildren] does not
/// walk that child anymore. /// walk that child anymore.
/// ///
/// The element will still have a valid parent when this is called. After this /// The element will still have a valid parent when this is called, and the
/// is called, [deactivateChild] is called to sever the link to this object. /// child's [Element.slot] value will be valid in the context of that parent.
/// After this is called, [deactivateChild] is called to sever the link to
/// this object.
/// ///
/// The [update] is responsible for updating or creating the new child that /// The [update] is responsible for updating or creating the new child that
/// will replace this [child]. /// will replace this [child].
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment