Chromium Code Reviews| Index: tools/dom/templates/html/impl/impl_Node.darttemplate |
| diff --git a/tools/dom/templates/html/impl/impl_Node.darttemplate b/tools/dom/templates/html/impl/impl_Node.darttemplate |
| index a13be659bc61145b1627ee6d5381739d23a76cba..5d705f74d436c7594e258fc4aa5098a5447dab15 100644 |
| --- a/tools/dom/templates/html/impl/impl_Node.darttemplate |
| +++ b/tools/dom/templates/html/impl/impl_Node.darttemplate |
| @@ -9,7 +9,7 @@ part of $LIBRARYNAME; |
| * the actual child nodes of an element until strictly necessary greatly |
| * improving performance for the typical cases where it is not required. |
| */ |
| -class _ChildNodeListLazy implements List { |
| +class _ChildNodeListLazy extends ListBase<Node> { |
| final Node _this; |
| _ChildNodeListLazy(this._this); |
| @@ -51,14 +51,6 @@ $else |
| } |
| $endif |
| - Node min([int compare(Node a, Node b)]) { |
| - return IterableMixinWorkaround.min(this, compare); |
| - } |
| - |
| - Node max([int compare(Node a, Node b)]) { |
| - return IterableMixinWorkaround.max(this, compare); |
| - } |
| - |
| void add(Node value) { |
| _this.append(value); |
| } |
| @@ -114,19 +106,33 @@ $endif |
| } |
| void removeAll(Iterable elements) { |
|
floitsch
2013/04/08 15:33:14
Explain why this doesn't come from the ListBase.
Lasse Reichstein Nielsen
2013/04/11 07:28:19
Done.
|
| - IterableMixinWorkaround.removeAll(this, elements); |
| + for (var element in elements) { |
| + remove(element); |
| + } |
| + } |
| + |
| + void _filter(bool test(Node node), bool removeMatching) { |
| + Node child = _this.$dom_firstChild; |
| + while (child != null) { |
| + Node nextChild = child.nextSibling; |
| + if (test(child) == removeMatching) { |
| + _this.$dom_removeChild(child); |
| + } |
| + child = nextChild; |
| + } |
| } |
| void retainAll(Iterable elements) { |
| - IterableMixinWorkaround.retainAll(this, elements); |
| + Set retainSet = (elements is Set) ? elements : elements.toSet(); |
| + _filter(retainSet.contains, false); |
| } |
| void removeWhere(bool test(Node node)) { |
| - IterableMixinWorkaround.removeWhere(this, test); |
| + _filter(test, true); |
|
floitsch
2013/04/08 15:33:14
ditto.
Lasse Reichstein Nielsen
2013/04/11 07:28:19
Done.
|
| } |
| void retainWhere(bool test(Node node)) { |
| - IterableMixinWorkaround.retainWhere(this, test); |
| + _filter(test, false); |
| } |
| void clear() { |
| @@ -139,42 +145,6 @@ $endif |
| Iterator<Node> get iterator => _this.$dom_childNodes.iterator; |
| - // TODO(jacobr): We can implement these methods much more efficiently by |
| - // looking up the nodeList only once instead of once per iteration. |
| - bool contains(Node element) => IterableMixinWorkaround.contains(this, element); |
| - |
| - void forEach(void f(Node element)) => IterableMixinWorkaround.forEach(this, f); |
| - |
| - dynamic reduce(dynamic initialValue, |
| - dynamic combine(dynamic previousValue, Node element)) { |
| - return IterableMixinWorkaround.reduce(this, initialValue, combine); |
| - } |
| - |
| - dynamic fold(dynamic initialValue, |
| - dynamic combine(dynamic previousValue, Node element)) { |
| - return IterableMixinWorkaround.fold(this, initialValue, combine); |
| - } |
| - |
| - String join([String separator]) { |
| - return IterableMixinWorkaround.joinList(this, separator); |
| - } |
| - |
| - Iterable map(f(Node element)) { |
| - return IterableMixinWorkaround.mapList(this, f); |
| - } |
| - |
| - Iterable<Node> where(bool f(Node element)) { |
| - return IterableMixinWorkaround.where(this, f); |
| - } |
| - |
| - Iterable expand(Iterable f(Node element)) { |
| - return IterableMixinWorkaround.expand(this, f); |
| - } |
| - |
| - bool every(bool f(Node element)) => IterableMixinWorkaround.every(this, f); |
| - |
| - bool any(bool f(Node element)) => IterableMixinWorkaround.any(this, f); |
| - |
| List<Node> toList({ bool growable: true }) => |
| new List<Node>.from(this, growable: growable); |
| Set<Node> toSet() => new Set<Node>.from(this); |
| @@ -183,54 +153,12 @@ $endif |
| // From List<Node>: |
| - Iterable<Node> take(int n) { |
| - return IterableMixinWorkaround.takeList(this, n); |
| - } |
| - |
| - Iterable<Node> takeWhile(bool test(Node value)) { |
| - return IterableMixinWorkaround.takeWhile(this, test); |
| - } |
| - |
| - Iterable<Node> skip(int n) { |
| - return IterableMixinWorkaround.skipList(this, n); |
| - } |
| - |
| - Iterable<Node> skipWhile(bool test(Node value)) { |
| - return IterableMixinWorkaround.skipWhile(this, test); |
| - } |
| - |
| - Node firstWhere(bool test(Node value), {Node orElse()}) { |
| - return IterableMixinWorkaround.firstWhere(this, test, orElse); |
| - } |
| - |
| - Node lastWhere(bool test(Node value), {Node orElse()}) { |
| - return IterableMixinWorkaround.lastWhereList(this, test, orElse); |
| - } |
| - |
| - Node singleWhere(bool test(Node value)) { |
| - return IterableMixinWorkaround.singleWhere(this, test); |
| - } |
| - |
| - Node elementAt(int index) { |
| - return this[index]; |
| - } |
| - |
| - Iterable<Node> get reversed { |
| - return IterableMixinWorkaround.reversedList(this); |
| - } |
| - |
| // TODO(jacobr): this could be implemented for child node lists. |
| // The exception we throw here is misleading. |
| void sort([int compare(Node a, Node b)]) { |
| throw new UnsupportedError("Cannot sort immutable List."); |
| } |
| - int indexOf(Node element, [int start = 0]) => |
| - Lists.indexOf(this, element, start, this.length); |
| - |
| - int lastIndexOf(Node element, [int start = 0]) => |
| - Lists.lastIndexOf(this, element, start); |
| - |
| // FIXME: implement these. |
| void setRange(int start, int rangeLength, List<Node> from, [int startFrom]) { |
| throw new UnsupportedError( |
| @@ -270,8 +198,6 @@ $endif |
| } |
| Node operator[](int index) => _this.$dom_childNodes[index]; |
| - |
| - Map<int, Node> asMap() => IterableMixinWorkaround.asMapList(this); |
| } |
| $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |