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

Unified Diff: tools/dom/templates/immutable_list_mixin.darttemplate

Issue 14619013: Explicitly implementing some DOM iterable APIs for performance (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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
« tools/dom/scripts/systemnative.py ('K') | « tools/dom/scripts/systemnative.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/templates/immutable_list_mixin.darttemplate
diff --git a/tools/dom/templates/immutable_list_mixin.darttemplate b/tools/dom/templates/immutable_list_mixin.darttemplate
index e9bffe58e4524018b0aefc00e13bd149a0d22d17..7e2d68d035145748f5d4e109929207441ba76ad2 100644
--- a/tools/dom/templates/immutable_list_mixin.darttemplate
+++ b/tools/dom/templates/immutable_list_mixin.darttemplate
@@ -12,4 +12,44 @@ $if DEFINE_LENGTH_SETTER
}
$endif
+ $E get first {
+ if (this.length > 0) {
+$if DART2JS
+ return JS('$E', '#[0]', this);
+$else
+ return this[0];
+$endif
+ }
+ throw new StateError("No elements");
+ }
+
+ $E get last {
+ int len = this.length;
+ if (len > 0) {
+$if DART2JS
+ return JS('$E', '#[#]', this, len - 1);
+$else
+ return this[len - 1];
+$endif
+ }
+ throw new StateError("No elements");
+ }
+
+ $E get single {
+ int len = this.length;
+ if (len == 1) {
+$if DART2JS
+ return JS('$E', '#[0]', this);
+$else
+ return this[0];
+$endif
+ }
+ if (len == 0) throw new StateError("No elements");
+ throw new StateError("More than one element");
+ }
+
+ $E elementAt(int index) {
sra1 2013/05/09 19:55:50 nit: could be =>
+ return this[index];
+ }
+
// -- end List<$E> mixins.
« tools/dom/scripts/systemnative.py ('K') | « tools/dom/scripts/systemnative.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698