Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Unified Diff: lib/html/templates/html/impl/impl_DocumentFragment.darttemplate

Issue 11033007: Revert "Removing ElementList (splitting out removing NodeList into a separate CL)." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/html/templates/html/impl/impl_DocumentFragment.darttemplate
diff --git a/lib/html/templates/html/impl/impl_DocumentFragment.darttemplate b/lib/html/templates/html/impl/impl_DocumentFragment.darttemplate
index 58204ae983db75956ae2b75be8d86e093c70924c..8636677cb4398e7d01179941758abe236332fc2a 100644
--- a/lib/html/templates/html/impl/impl_DocumentFragment.darttemplate
+++ b/lib/html/templates/html/impl/impl_DocumentFragment.darttemplate
@@ -2,11 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-class _FilteredElementList implements List {
+class FilteredElementList implements ElementList {
final Node _node;
final NodeList _childNodes;
- _FilteredElementList(Node node): _childNodes = node.nodes, _node = node;
+ FilteredElementList(Node node): _childNodes = node.nodes, _node = node;
// We can't memoize this, since it's possible that children will be messed
// with externally to this class.
@@ -15,6 +15,16 @@ class _FilteredElementList implements List {
List<Element> get _filtered =>
new List.from(_childNodes.filter((n) => n is Element));
+ // Don't use _filtered.first so we can short-circuit once we find an element.
+ Element get first {
+ for (final node in _childNodes) {
+ if (node is Element) {
+ return node;
+ }
+ }
+ return null;
+ }
+
void forEach(void f(Element element)) {
_filtered.forEach(f);
}
@@ -125,11 +135,11 @@ class _FrozenCSSClassSet extends _CssClassSet {
}
class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
- List<Element> _elements;
+ ElementList _elements;
- List<Element> get elements {
+ ElementList get elements {
if (_elements == null) {
- _elements = new _FilteredElementList(this);
+ _elements = new FilteredElementList(this);
}
return _elements;
}
@@ -174,8 +184,7 @@ class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
case "beforebegin": return null;
case "afterend": return null;
case "afterbegin":
- var first = this.nodes.length > 0 ? this.nodes[0] : null;
- this.insertBefore(node, first);
+ this.insertBefore(node, this.nodes.first);
return node;
case "beforeend":
this.nodes.add(node);
@@ -224,12 +233,7 @@ class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
String get tagName => "";
String get webkitdropzone => "";
String get webkitRegionOverflow => "";
- Element get $m_firstElementChild {
- if (elements.length > 0) {
- return elements[0];
- }
- return null;
- }
+ Element get $m_firstElementChild() => elements.first();
Element get $m_lastElementChild() => elements.last();
Element get nextElementSibling => null;
Element get previousElementSibling => null;
« no previous file with comments | « lib/html/templates/html/dartium/html_dartium.darttemplate ('k') | lib/html/templates/html/impl/impl_Element.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698