Commit 87adaf3f authored by Hixie's avatar Hixie

RenderObjectWrapper cleanup and new asserts.

- Clarify comment about RenderObjectWrapper.
- Assert that we never sync a RenderObjectWrapper with an instance of a different type.
- Assert that MultiChildRenderObjectWrapper subclasses always have multi-child RenderObjects.
- Assert that renderObject doesn't change identity when syncing.
- Make searchForOldNode() return void since the return value is ignored.
- Remove code that handled renderObject changing during sync.
parent 2c44ed0f
...@@ -864,10 +864,10 @@ void _scheduleComponentForRender(Component component) { ...@@ -864,10 +864,10 @@ void _scheduleComponentForRender(Component component) {
} }
} }
// RenderObjectWrappers correspond to a desired state of a RenderObject. // RenderObjectWrappers correspond to a desired state of a
// They are fully immutable, with one exception: A Widget which is a // RenderObject. They are fully immutable, except that a Widget which
// Component which lives within an MultiChildRenderObjectWrapper's // is a Component which lives within a RenderObjectWrapper's children
// children list, may be replaced with the "old" instance if it has // list may be in-place replaced with the "old" instance if it has
// become stateful. // become stateful.
abstract class RenderObjectWrapper extends Widget { abstract class RenderObjectWrapper extends Widget {
...@@ -911,7 +911,7 @@ abstract class RenderObjectWrapper extends Widget { ...@@ -911,7 +911,7 @@ abstract class RenderObjectWrapper extends Widget {
if (_ancestor is RenderObjectWrapper) if (_ancestor is RenderObjectWrapper)
_ancestor.insertChildRoot(this, slot); _ancestor.insertChildRoot(this, slot);
} else { } else {
assert(old is RenderObjectWrapper); assert(old.runtimeType == runtimeType);
_renderObject = old.renderObject; _renderObject = old.renderObject;
_ancestor = old._ancestor; _ancestor = old._ancestor;
assert(_renderObject != null); assert(_renderObject != null);
...@@ -1088,9 +1088,9 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { ...@@ -1088,9 +1088,9 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper {
void syncRenderObject(MultiChildRenderObjectWrapper old) { void syncRenderObject(MultiChildRenderObjectWrapper old) {
super.syncRenderObject(old); super.syncRenderObject(old);
final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer final ContainerRenderObjectMixin renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer
if (renderObject is! ContainerRenderObjectMixin) assert(renderObject is ContainerRenderObjectMixin);
return; assert(old == null || old.renderObject == renderObject);
var startIndex = 0; var startIndex = 0;
var endIndex = children.length; var endIndex = children.length;
...@@ -1155,28 +1155,21 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { ...@@ -1155,28 +1155,21 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper {
} }
} }
bool searchForOldNode() { void searchForOldNode() {
if (currentNode.key == null) if (currentNode.key == null)
return false; // never re-order these nodes return; // never re-order these nodes
ensureOldIdMap(); ensureOldIdMap();
oldNode = oldNodeIdMap[currentNode.key]; oldNode = oldNodeIdMap[currentNode.key];
if (oldNode == null) if (oldNode == null)
return false; return;
oldNodeIdMap[currentNode.key] = null; // mark it reordered oldNodeIdMap[currentNode.key] = null; // mark it reordered
assert(renderObject is ContainerRenderObjectMixin); assert(renderObject is ContainerRenderObjectMixin);
assert(old.renderObject is ContainerRenderObjectMixin); assert(old.renderObject is ContainerRenderObjectMixin);
assert(oldNode.renderObject != null); assert(oldNode.renderObject != null);
if (old.renderObject == renderObject) { renderObject.move(oldNode.renderObject, before: nextSibling);
renderObject.move(oldNode.renderObject, before: nextSibling);
} else {
(old.renderObject as ContainerRenderObjectMixin).remove(oldNode.renderObject); // TODO(ianh): Remove cast once the analyzer is cleverer
renderObject.add(oldNode.renderObject, before: nextSibling);
}
return true;
} }
// Scan forwards, this time we may re-order; // Scan forwards, this time we may re-order;
......
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