| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 190 } |
| 204 | 191 |
| 205 Node operator[](int index) => _this.$dom_childNodes[index]; | 192 Node operator[](int index) => _this.$dom_childNodes[index]; |
| 206 } | 193 } |
| 207 | 194 |
| 208 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 195 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 209 List<Node> get nodes { | 196 List<Node> get nodes { |
| 210 return new _ChildNodeListLazy(this); | 197 return new _ChildNodeListLazy(this); |
| 211 } | 198 } |
| 212 | 199 |
| 213 void set nodes(Collection<Node> value) { | 200 void set nodes(Iterable<Node> value) { |
| 214 // Copy list first since we don't want liveness during iteration. | 201 // Copy list first since we don't want liveness during iteration. |
| 215 // TODO(jacobr): there is a better way to do this. | 202 // TODO(jacobr): there is a better way to do this. |
| 216 List copy = new List.from(value); | 203 List copy = new List.from(value); |
| 217 text = ''; | 204 text = ''; |
| 218 for (Node node in copy) { | 205 for (Node node in copy) { |
| 219 append(node); | 206 append(node); |
| 220 } | 207 } |
| 221 } | 208 } |
| 222 | 209 |
| 223 /** | 210 /** |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } | 343 } |
| 357 | 344 |
| 358 /** | 345 /** |
| 359 * Print out a String representation of this Node. | 346 * Print out a String representation of this Node. |
| 360 */ | 347 */ |
| 361 String toString() => localName == null ? | 348 String toString() => localName == null ? |
| 362 (nodeValue == null ? super.toString() : nodeValue) : localName; | 349 (nodeValue == null ? super.toString() : nodeValue) : localName; |
| 363 | 350 |
| 364 $!MEMBERS | 351 $!MEMBERS |
| 365 } | 352 } |
| OLD | NEW |