| 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 /** | 5 /** |
| 6 * Lazy implementation of the child nodes of an element that does not request | 6 * Lazy implementation of the child nodes of an element that does not request |
| 7 * the actual child nodes of an element until strictly necessary greatly | 7 * the actual child nodes of an element until strictly necessary greatly |
| 8 * improving performance for the typical cases where it is not required. | 8 * improving performance for the typical cases where it is not required. |
| 9 */ | 9 */ |
| 10 class _ChildNodeListLazy implements NodeList { | 10 class _ChildNodeListLazy implements NodeList { |
| 11 final _NodeImpl _this; | 11 final _NodeImpl _this; |
| 12 | 12 |
| 13 _ChildNodeListLazy(this._this); | 13 _ChildNodeListLazy(this._this); |
| 14 | 14 |
| 15 | 15 |
| 16 $if DART2JS | 16 $if DART2JS |
| 17 _NodeImpl get first() => JS('_NodeImpl', '#.firstChild', _this); | 17 _NodeImpl get first => JS('_NodeImpl', '#.firstChild', _this); |
| 18 _NodeImpl last() => JS('_NodeImpl', '#.lastChild', _this); | 18 _NodeImpl last() => JS('_NodeImpl', '#.lastChild', _this); |
| 19 $else | 19 $else |
| 20 _NodeImpl get first() => _this.$dom_firstChild; | 20 _NodeImpl get first => _this.$dom_firstChild; |
| 21 _NodeImpl last() => _this.$dom_lastChild; | 21 _NodeImpl last() => _this.$dom_lastChild; |
| 22 $endif | 22 $endif |
| 23 | 23 |
| 24 void add(_NodeImpl value) { | 24 void add(_NodeImpl value) { |
| 25 _this.$dom_appendChild(value); | 25 _this.$dom_appendChild(value); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void addLast(_NodeImpl value) { | 28 void addLast(_NodeImpl value) { |
| 29 _this.$dom_appendChild(value); | 29 _this.$dom_appendChild(value); |
| 30 } | 30 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 throw new UnsupportedOperationException( | 96 throw new UnsupportedOperationException( |
| 97 "Cannot insertRange on immutable List."); | 97 "Cannot insertRange on immutable List."); |
| 98 } | 98 } |
| 99 NodeList getRange(int start, int rangeLength) => | 99 NodeList getRange(int start, int rangeLength) => |
| 100 new _NodeListWrapper(_Lists.getRange(this, start, rangeLength, <Node>[])); | 100 new _NodeListWrapper(_Lists.getRange(this, start, rangeLength, <Node>[])); |
| 101 | 101 |
| 102 // -- end List<Node> mixins. | 102 // -- end List<Node> mixins. |
| 103 | 103 |
| 104 // TODO(jacobr): benchmark whether this is more efficient or whether caching | 104 // TODO(jacobr): benchmark whether this is more efficient or whether caching |
| 105 // a local copy of $dom_childNodes is more efficient. | 105 // a local copy of $dom_childNodes is more efficient. |
| 106 int get length() => _this.$dom_childNodes.length; | 106 int get length => _this.$dom_childNodes.length; |
| 107 | 107 |
| 108 _NodeImpl operator[](int index) => _this.$dom_childNodes[index]; | 108 _NodeImpl operator[](int index) => _this.$dom_childNodes[index]; |
| 109 } | 109 } |
| 110 | 110 |
| 111 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 111 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 112 _ChildNodeListLazy get nodes() { | 112 _ChildNodeListLazy get nodes { |
| 113 return new _ChildNodeListLazy(this); | 113 return new _ChildNodeListLazy(this); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void set nodes(Collection<Node> value) { | 116 void set nodes(Collection<Node> value) { |
| 117 // Copy list first since we don't want liveness during iteration. | 117 // Copy list first since we don't want liveness during iteration. |
| 118 // TODO(jacobr): there is a better way to do this. | 118 // TODO(jacobr): there is a better way to do this. |
| 119 List copy = new List.from(value); | 119 List copy = new List.from(value); |
| 120 text = ''; | 120 text = ''; |
| 121 for (Node node in copy) { | 121 for (Node node in copy) { |
| 122 $dom_appendChild(node); | 122 $dom_appendChild(node); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 137 final _NodeImpl parent = this.parent; | 137 final _NodeImpl parent = this.parent; |
| 138 parent.$dom_replaceChild(otherNode, this); | 138 parent.$dom_replaceChild(otherNode, this); |
| 139 } catch (e) { | 139 } catch (e) { |
| 140 | 140 |
| 141 }; | 141 }; |
| 142 return this; | 142 return this; |
| 143 } | 143 } |
| 144 | 144 |
| 145 $!MEMBERS | 145 $!MEMBERS |
| 146 } | 146 } |
| OLD | NEW |