Merge pull request #897 from Hixie/sync-children
Provide a fast path for MultiChildRenderObjectWrapper.syncRenderObject() when the children lists are identical.
This commit is contained in:
commit
1e61314ed5
@ -998,6 +998,9 @@ abstract class RenderObjectWrapper extends Widget {
|
|||||||
|
|
||||||
// for use by subclasses that manage their children using lists
|
// for use by subclasses that manage their children using lists
|
||||||
void syncChildren(List<Widget> newChildren, List<Widget> oldChildren) {
|
void syncChildren(List<Widget> newChildren, List<Widget> oldChildren) {
|
||||||
|
assert(newChildren != null);
|
||||||
|
assert(oldChildren != null);
|
||||||
|
assert(!identical(newChildren, oldChildren));
|
||||||
|
|
||||||
// This attempts to diff the new child list (this.children) with
|
// This attempts to diff the new child list (this.children) with
|
||||||
// the old child list (old.children), and update our renderObject
|
// the old child list (old.children), and update our renderObject
|
||||||
@ -1257,7 +1260,19 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper {
|
|||||||
|
|
||||||
void syncRenderObject(MultiChildRenderObjectWrapper old) {
|
void syncRenderObject(MultiChildRenderObjectWrapper old) {
|
||||||
super.syncRenderObject(old);
|
super.syncRenderObject(old);
|
||||||
syncChildren(children, old == null ? const <Widget>[] : old.children);
|
List<Widget> oldChildren = old == null ? const <Widget>[] : old.children;
|
||||||
|
if (oldChildren == children) {
|
||||||
|
int index = children.length;
|
||||||
|
Widget nextSibling = null;
|
||||||
|
while (index > 0) {
|
||||||
|
index -= 1;
|
||||||
|
Widget child = children[index];
|
||||||
|
nextSibling = syncChild(child, child, nextSibling);
|
||||||
|
children[index] = nextSibling;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
syncChildren(children, oldChildren);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user