From 204c0736155ac3f39b3801b69e8ad2ea85ca0e81 Mon Sep 17 00:00:00 2001 From: Hixie Date: Thu, 27 Aug 2015 14:49:29 -0700 Subject: [PATCH] Provide a fast path for MultiChildRenderObjectWrapper.syncRenderObject() when the children lists are identical. This isn't so much for performance so much as because I don't want to have to keep checking that the main syncChildren() function maintains the invariant of not screwing up when the two lists are actually the same list. --- packages/flutter/lib/widgets/framework.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/widgets/framework.dart b/packages/flutter/lib/widgets/framework.dart index 5859650745..90c0269211 100644 --- a/packages/flutter/lib/widgets/framework.dart +++ b/packages/flutter/lib/widgets/framework.dart @@ -1001,6 +1001,9 @@ abstract class RenderObjectWrapper extends Widget { // for use by subclasses that manage their children using lists void syncChildren(List newChildren, List oldChildren) { + assert(newChildren != null); + assert(oldChildren != null); + assert(!identical(newChildren, oldChildren)); // This attempts to diff the new child list (this.children) with // the old child list (old.children), and update our renderObject @@ -1260,7 +1263,19 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { void syncRenderObject(MultiChildRenderObjectWrapper old) { super.syncRenderObject(old); - syncChildren(children, old == null ? const [] : old.children); + List oldChildren = old == null ? const [] : 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); + } } }