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

Side by Side Diff: test/dart_codegen/expect/core/list.dart

Issue 1071393007: fuse List and js Array together and a few other misc fixes. (Closed) Base URL: git@github.com:dart-lang/dart-dev-compiler.git@master
Patch Set: ptal Created 5 years, 8 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
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | test/dart_codegen/expect/core/stopwatch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 part of dart.core; 1 part of dart.core;
2 @SupportJsExtensionMethod() @JsPeerInterface(name: 'Array') abstract class List <E> implements Iterable<E>, EfficientLength {external factory List([int length]) ; 2 @SupportJsExtensionMethod() @JsPeerInterface(name: 'Array') abstract class List <E> implements Iterable<E>, EfficientLength {external factory List([int length]) ;
3 external factory List.filled(int length, E fill); 3 external factory List.filled(int length, E fill);
4 external factory List.from(Iterable elements, { 4 external factory List.from(Iterable elements, {
5 bool growable : true} 5 bool growable : true}
6 ); 6 );
7 factory List.generate(int length, E generator(int index), { 7 factory List.generate(int length, E generator(int index), {
8 bool growable : true} 8 bool growable : true}
9 ) { 9 ) {
10 List<E> result; 10 List<E> result;
11 if (growable) { 11 if (growable) {
12 result = <E> []..length = length; 12 result = <E> []..length = length;
13 } 13 }
14 else { 14 else {
15 result = new List<E>(length); 15 result = new List<E>(length);
16 } 16 }
17 for (int i = 0; i < length; i++) { 17 for (int i = 0; i < length; i++) {
18 result[i] = generator(i); 18 result[i] = generator(i);
19 } 19 }
20 return result; 20 return result;
21 } 21 }
22 E operator [](int index); 22 checkMutable(reason) {
23 void operator []=(int index, E value); 23 }
24 int get length; 24 checkGrowable(reason) {
25 void set length(int newLength); 25 }
26 void add(E value); 26 Iterable<E> where(bool f(E element)) {
27 void addAll(Iterable<E> iterable); 27 return new IterableMixinWorkaround<E>().where(this, f);
28 Iterable<E> get reversed; 28 }
29 void sort([int compare(E a, E b)]); 29 Iterable expand(Iterable f(E element)) {
30 void shuffle([Random random]); 30 return IterableMixinWorkaround.expand(this, f);
31 int indexOf(E element, [int start = 0]); 31 }
32 int lastIndexOf(E element, [int start]); 32 void forEach(void f(E element)) {
33 void clear(); 33 int length = this.length;
34 void insert(int index, E element); 34 for (int i = 0; i < length; i++) {
35 void insertAll(int index, Iterable<E> iterable); 35 f(((__x9) => DEVC$RT.cast(__x9, dynamic, E, "CompositeCast", """line 153, co lumn 9 of dart:core/list.dart: """, __x9 is E, false))(JS('', '#[#]', this, i))) ;
36 void setAll(int index, Iterable<E> iterable); 36 if (length != this.length) {
37 bool remove(Object value); 37 throw new ConcurrentModificationError(this);
38 E removeAt(int index); 38 }
39 E removeLast(); 39 }
40 void removeWhere(bool test(E element)); 40 }
41 void retainWhere(bool test(E element)); 41 Iterable map(f(E element)) {
42 List<E> sublist(int start, [int end]); 42 return IterableMixinWorkaround.mapList(this, f);
43 Iterable<E> getRange(int start, int end); 43 }
44 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]); 44 String join([String separator = ""]) {
45 void removeRange(int start, int end); 45 var list = new List(this.length);
46 void fillRange(int start, int end, [E fillValue]); 46 for (int i = 0; i < this.length; i++) {
47 void replaceRange(int start, int end, Iterable<E> replacement); 47 list[i] = "${this[i]}";
48 Map<int, E> asMap(); 48 }
49 return ((__x10) => DEVC$RT.cast(__x10, dynamic, String, "DynamicCast", """lin e 169, column 12 of dart:core/list.dart: """, __x10 is String, true))(JS('String ', "#.join(#)", list, separator));
50 }
51 Iterable<E> take(int n) {
52 return new IterableMixinWorkaround<E>().takeList(this, n);
53 }
54 Iterable<E> takeWhile(bool test(E value)) {
55 return new IterableMixinWorkaround<E>().takeWhile(this, test);
56 }
57 Iterable<E> skip(int n) {
58 return new IterableMixinWorkaround<E>().skipList(this, n);
59 }
60 Iterable<E> skipWhile(bool test(E value)) {
61 return new IterableMixinWorkaround<E>().skipWhile(this, test);
62 }
63 E reduce(E combine(E value, E element)) {
64 return ((__x11) => DEVC$RT.cast(__x11, dynamic, E, "CompositeCast", """line 18 9, column 12 of dart:core/list.dart: """, __x11 is E, false))(IterableMixinWorka round.reduce(this, combine));
65 }
66 fold(initialValue, combine(previousValue, E element)) {
67 return IterableMixinWorkaround.fold(this, initialValue, combine);
68 }
69 E firstWhere(bool test(E value), {
70 E orElse()}
71 ) {
72 return ((__x12) => DEVC$RT.cast(__x12, dynamic, E, "CompositeCast", """line 19 7, column 12 of dart:core/list.dart: """, __x12 is E, false))(IterableMixinWorka round.firstWhere(this, test, orElse));
73 }
74 E lastWhere(bool test(E value), {
75 E orElse()}
76 ) {
77 return ((__x13) => DEVC$RT.cast(__x13, dynamic, E, "CompositeCast", """line 20 1, column 12 of dart:core/list.dart: """, __x13 is E, false))(IterableMixinWorka round.lastWhereList(this, test, orElse));
78 }
79 E singleWhere(bool test(E value)) {
80 return ((__x14) => DEVC$RT.cast(__x14, dynamic, E, "CompositeCast", """line 20 5, column 12 of dart:core/list.dart: """, __x14 is E, false))(IterableMixinWorka round.singleWhere(this, test));
81 }
82 E elementAt(int index) {
83 return this[index];
84 }
85 E get first {
86 if (length > 0) return this[0];
87 throw new StateError("No elements");
88 }
89 E get last {
90 if (length > 0) return this[length - 1];
91 throw new StateError("No elements");
92 }
93 E get single {
94 if (length == 1) return this[0];
95 if (length == 0) throw new StateError("No elements");
96 throw new StateError("More than one element");
97 }
98 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f);
99 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f);
100 void sort([int compare(E a, E b)]) {
101 checkMutable('sort');
102 IterableMixinWorkaround.sortList(this, compare);
103 }
104 bool contains(Object other) {
105 for (int i = 0; i < length; i++) {
106 if (this[i] == other) return true;
107 }
108 return false;
109 }
110 bool get isEmpty => length == 0;
111 bool get isNotEmpty => !isEmpty;
112 String toString() => ListBase.listToString(this);
113 List<E> toList({
114 bool growable : true}
115 ) {
116 if (growable) {
117 return new JSArray<E>.markGrowable(JS('', '#.slice()', this));
118 }
119 else {
120 return new JSArray<E>.markFixed(JS('', '#.slice()', this));
121 }
122 }
123 Set<E> toSet() => new Set<E>.from(this);
124 Iterator<E> get iterator => new ListIterator<E>(this);
125 int get hashCode => ((__x15) => DEVC$RT.cast(__x15, dynamic, int, "DynamicCast" , """line 262, column 23 of dart:core/list.dart: """, __x15 is int, true))(Primi tives.objectHashCode(this));
126 E operator [](int index) {
127 if (index is! int) throw new ArgumentError(index);
128 if (index >= length || index < 0) throw new RangeError.value(index);
129 return ((__x16) => DEVC$RT.cast(__x16, dynamic, E, "CompositeCast", """line 2 73, column 12 of dart:core/list.dart: """, __x16 is E, false))(JS('var', '#[#]', this, index));
130 }
131 void operator []=(int index, E value) {
132 checkMutable('indexed set');
133 if (index is! int) throw new ArgumentError(index);
134 if (index >= length || index < 0) throw new RangeError.value(index);
135 JS('void', r'#[#] = #', this, index, value);
136 }
137 int get length => ((__x17) => DEVC$RT.cast(__x17, dynamic, int, "DynamicCast", """line 292, column 21 of dart:core/list.dart: """, __x17 is int, true))(JS('JSU Int32', r'#.length', this));
138 void set length(int newLength) {
139 if (newLength is! int) throw new ArgumentError(newLength);
140 if (newLength < 0) throw new RangeError.value(newLength);
141 checkGrowable('set length');
142 JS('void', r'#.length = #', this, newLength);
143 }
144 void add(E value) {
145 checkGrowable('add');
146 JS('void', r'#.push(#)', this, value);
147 }
148 void addAll(Iterable<E> iterable) {
149 for (E e in iterable) {
150 this.add(e);
151 }
152 }
153 Iterable<E> get reversed => new IterableMixinWorkaround<E>().reversedList(this) ;
154 void sort([int compare(E a, E b)]) {
155 IterableMixinWorkaround.sortList(this, compare);
156 }
157 void shuffle([Random random]) {
158 IterableMixinWorkaround.shuffleList(this, random);
159 }
160 int indexOf(E element, [int start = 0]) {
161 return IterableMixinWorkaround.indexOfList(this, element, start);
162 }
163 int lastIndexOf(E element, [int start]) {
164 return IterableMixinWorkaround.lastIndexOfList(this, element, start);
165 }
166 void clear() {
167 length = 0;
168 }
169 void insert(int index, E element) {
170 if (index is! int) throw new ArgumentError(index);
171 if (index < 0 || index > length) {
172 throw new RangeError.value(index);
173 }
174 checkGrowable('insert');
175 JS('void', r'#.splice(#, 0, #)', this, index, element);
176 }
177 void insertAll(int index, Iterable<E> iterable) {
178 checkGrowable('insertAll');
179 IterableMixinWorkaround.insertAllList(this, index, iterable);
180 }
181 void setAll(int index, Iterable<E> iterable) {
182 checkMutable('setAll');
183 IterableMixinWorkaround.setAllList(this, index, iterable);
184 }
185 bool remove(Object element) {
186 checkGrowable('remove');
187 for (int i = 0; i < this.length; i++) {
188 if (this[i] == value) {
189 JS('var', r'#.splice(#, 1)', this, i);
190 return true;
191 }
192 }
193 return false;
194 }
195 E removeAt(int index) {
196 if (index is! int) throw new ArgumentError(index);
197 if (index < 0 || index >= length) {
198 throw new RangeError.value(index);
199 }
200 checkGrowable('removeAt');
201 return ((__x18) => DEVC$RT.cast(__x18, dynamic, E, "CompositeCast", """line 5 24, column 12 of dart:core/list.dart: """, __x18 is E, false))(JS('var', r'#.spl ice(#, 1)[0]', this, index));
202 }
203 E removeLast() {
204 checkGrowable('removeLast');
205 if (length == 0) throw new RangeError.value(-1);
206 return ((__x19) => DEVC$RT.cast(__x19, dynamic, E, "CompositeCast", """line 5 35, column 12 of dart:core/list.dart: """, __x19 is E, false))(JS('var', r'#.pop ()', this));
207 }
208 void removeWhere(bool test(E element)) {
209 IterableMixinWorkaround.removeWhereList(this, test);
210 }
211 void retainWhere(bool test(E element)) {
212 IterableMixinWorkaround.removeWhereList(this, (E element) => !test(element));
213 }
214 List<E> sublist(int start, [int end]) {
215 checkNull(start);
216 if (start is! int) throw new ArgumentError(start);
217 if (start < 0 || start > length) {
218 throw new RangeError.range(start, 0, length);
219 }
220 if (end == null) {
221 end = length;
222 }
223 else {
224 if (end is! int) throw new ArgumentError(end);
225 if (end < start || end > length) {
226 throw new RangeError.range(end, start, length);
227 }
228 }
229 if (start == end) return <E> [];
230 return new JSArray<E>.markGrowable(JS('', r'#.slice(#, #)', this, start, end) );
231 }
232 Iterable<E> getRange(int start, int end) {
233 return new IterableMixinWorkaround<E>().getRangeList(this, start, end);
234 }
235 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
236 checkMutable('set range');
237 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount);
238 }
239 void removeRange(int start, int end) {
240 checkGrowable('removeRange');
241 int receiverLength = this.length;
242 if (start < 0 || start > receiverLength) {
243 throw new RangeError.range(start, 0, receiverLength);
244 }
245 if (end < start || end > receiverLength) {
246 throw new RangeError.range(end, start, receiverLength);
247 }
248 Lists.copy(this, end, this, start, receiverLength - end);
249 this.length = receiverLength - (end - start);
250 }
251 void fillRange(int start, int end, [E fillValue]) {
252 checkMutable('fill range');
253 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue);
254 }
255 void replaceRange(int start, int end, Iterable<E> replacement) {
256 checkGrowable('removeRange');
257 IterableMixinWorkaround.replaceRangeList(this, start, end, replacement);
258 }
259 Map<int, E> asMap() {
260 return new IterableMixinWorkaround<E>().asMapList(this);
261 }
49 } 262 }
OLDNEW
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | test/dart_codegen/expect/core/stopwatch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698