| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Lazy implementation of the child nodes of an element that does not request | 8 * Lazy implementation of the child nodes of an element that does not request |
| 9 * the actual child nodes of an element until strictly necessary greatly | 9 * the actual child nodes of an element until strictly necessary greatly |
| 10 * improving performance for the typical cases where it is not required. | 10 * improving performance for the typical cases where it is not required. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return result; | 98 return result; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void remove(Object object) { | 101 void remove(Object object) { |
| 102 if (object is! Node) return; | 102 if (object is! Node) return; |
| 103 Node node = object; | 103 Node node = object; |
| 104 if (!identical(_this, node.parentNode)) return; | 104 if (!identical(_this, node.parentNode)) return; |
| 105 _this.$dom_removeChild(node); | 105 _this.$dom_removeChild(node); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void removeAll(Iterable elements) { | |
| 109 // This is not using the default removeAll from ListBase because | |
| 110 // DOM nodes can be efficiently removed in constant time. | |
| 111 for (var element in elements) { | |
| 112 remove(element); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 void _filter(bool test(Node node), bool removeMatching) { | 108 void _filter(bool test(Node node), bool removeMatching) { |
| 117 // This implementation of removeWhere/retainWhere is more efficient | 109 // This implementation of removeWhere/retainWhere is more efficient |
| 118 // than the default in ListBase. Child nodes can be removed in constant | 110 // than the default in ListBase. Child nodes can be removed in constant |
| 119 // time. | 111 // time. |
| 120 Node child = _this.$dom_firstChild; | 112 Node child = _this.$dom_firstChild; |
| 121 while (child != null) { | 113 while (child != null) { |
| 122 Node nextChild = child.nextSibling; | 114 Node nextChild = child.nextSibling; |
| 123 if (test(child) == removeMatching) { | 115 if (test(child) == removeMatching) { |
| 124 _this.$dom_removeChild(child); | 116 _this.$dom_removeChild(child); |
| 125 } | 117 } |
| 126 child = nextChild; | 118 child = nextChild; |
| 127 } | 119 } |
| 128 } | 120 } |
| 129 | 121 |
| 130 void retainAll(Iterable elements) { | |
| 131 Set retainSet = (elements is Set) ? elements : elements.toSet(); | |
| 132 _filter(retainSet.contains, false); | |
| 133 } | |
| 134 | |
| 135 void removeWhere(bool test(Node node)) { | 122 void removeWhere(bool test(Node node)) { |
| 136 _filter(test, true); | 123 _filter(test, true); |
| 137 } | 124 } |
| 138 | 125 |
| 139 void retainWhere(bool test(Node node)) { | 126 void retainWhere(bool test(Node node)) { |
| 140 _filter(test, false); | 127 _filter(test, false); |
| 141 } | 128 } |
| 142 | 129 |
| 143 void clear() { | 130 void clear() { |
| 144 _this.text = ''; | 131 _this.text = ''; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 192 } |
| 206 | 193 |
| 207 Node operator[](int index) => _this.$dom_childNodes[index]; | 194 Node operator[](int index) => _this.$dom_childNodes[index]; |
| 208 } | 195 } |
| 209 | 196 |
| 210 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 197 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 211 List<Node> get nodes { | 198 List<Node> get nodes { |
| 212 return new _ChildNodeListLazy(this); | 199 return new _ChildNodeListLazy(this); |
| 213 } | 200 } |
| 214 | 201 |
| 215 void set nodes(Collection<Node> value) { | 202 void set nodes(Iterable<Node> value) { |
| 216 // Copy list first since we don't want liveness during iteration. | 203 // Copy list first since we don't want liveness during iteration. |
| 217 // TODO(jacobr): there is a better way to do this. | 204 // TODO(jacobr): there is a better way to do this. |
| 218 List copy = new List.from(value); | 205 List copy = new List.from(value); |
| 219 text = ''; | 206 text = ''; |
| 220 for (Node node in copy) { | 207 for (Node node in copy) { |
| 221 append(node); | 208 append(node); |
| 222 } | 209 } |
| 223 } | 210 } |
| 224 | 211 |
| 225 /** | 212 /** |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 345 } |
| 359 | 346 |
| 360 /** | 347 /** |
| 361 * Print out a String representation of this Node. | 348 * Print out a String representation of this Node. |
| 362 */ | 349 */ |
| 363 String toString() => localName == null ? | 350 String toString() => localName == null ? |
| 364 (nodeValue == null ? super.toString() : nodeValue) : localName; | 351 (nodeValue == null ? super.toString() : nodeValue) : localName; |
| 365 | 352 |
| 366 $!MEMBERS | 353 $!MEMBERS |
| 367 } | 354 } |
| OLD | NEW |