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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // -- start List<$E> mixins. 1 // -- start List<$E> mixins.
2 // $E is the element type. 2 // $E is the element type.
3 3
4 $if DEFINE_LENGTH_AS_NUM_ITEMS 4 $if DEFINE_LENGTH_AS_NUM_ITEMS
5 // SVG Collections expose numberOfItems rather than length. 5 // SVG Collections expose numberOfItems rather than length.
6 int get length => numberOfItems; 6 int get length => numberOfItems;
7 $endif 7 $endif
8 8
9 $if DEFINE_LENGTH_SETTER 9 $if DEFINE_LENGTH_SETTER
10 void set length(int value) { 10 void set length(int value) {
11 throw new UnsupportedError("Cannot resize immutable List."); 11 throw new UnsupportedError("Cannot resize immutable List.");
12 } 12 }
13 $endif 13 $endif
14 14
15 $E get first {
16 if (this.length > 0) {
17 $if DART2JS
18 return JS('$E', '#[0]', this);
19 $else
20 return this[0];
21 $endif
22 }
23 throw new StateError("No elements");
24 }
25
26 $E get last {
27 int len = this.length;
28 if (len > 0) {
29 $if DART2JS
30 return JS('$E', '#[#]', this, len - 1);
31 $else
32 return this[len - 1];
33 $endif
34 }
35 throw new StateError("No elements");
36 }
37
38 $E get single {
39 int len = this.length;
40 if (len == 1) {
41 $if DART2JS
42 return JS('$E', '#[0]', this);
43 $else
44 return this[0];
45 $endif
46 }
47 if (len == 0) throw new StateError("No elements");
48 throw new StateError("More than one element");
49 }
50
51 $E elementAt(int index) {
sra1 2013/05/09 19:55:50 nit: could be =>
52 return this[index];
53 }
54
15 // -- end List<$E> mixins. 55 // -- end List<$E> mixins.
OLDNEW
« 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