Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
perf(nodecursor): do not grow/shrink the nodes list
Browse files Browse the repository at this point in the history
This also enables one to construct a NodeCursor with a fixed size list
of nodes.
  • Loading branch information
chirayuk committed Aug 7, 2014
1 parent ea0e0ef commit 1ab510d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/core_dom/node_cursor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ part of angular.core.dom_internal;

class NodeCursor {
final stack = [];
List<dom.Node> elements;
List<dom.Node> elements; // may be a fixed length list.
int index = 0;

NodeCursor(this.elements);
Expand All @@ -29,21 +29,15 @@ class NodeCursor {
index = stack.removeLast();
}

void insertAnchorBefore(String name) {
var parent = current.parentNode;
var anchor = new dom.Comment('ANCHOR: $name');
elements.insert(index++, anchor);
if (parent != null) parent.insertBefore(anchor, current);
}

NodeCursor replaceWithAnchor(String name) {
insertAnchorBefore(name);
var childCursor = remove();
index--;
return childCursor;
var element = current;
var parent = element.parentNode;
var anchor = new dom.Comment('ANCHOR: $name');
if (parent != null) parent.insertBefore(anchor, element);
element.remove();
elements[index] = anchor;
return new NodeCursor([element]);
}

NodeCursor remove() => new NodeCursor([elements.removeAt(index)..remove()]);

String toString() => "[NodeCursor: $elements $index]";
}

0 comments on commit 1ab510d

Please sign in to comment.