| 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 part of _interceptors; | 5 part of _interceptors; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The interceptor class for [List]. The compiler recognizes this | 8 * The interceptor class for [List]. The compiler recognizes this |
| 9 * class as an interceptor, and changes references to [:this:] to | 9 * class as an interceptor, and changes references to [:this:] to |
| 10 * actually use the receiver of the method, which is generated as an extra | 10 * actually use the receiver of the method, which is generated as an extra |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // This could, and should, be optimized. | 140 // This could, and should, be optimized. |
| 141 IterableMixinWorkaround.removeWhereList(this, test); | 141 IterableMixinWorkaround.removeWhereList(this, test); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void retainWhere(bool test(E element)) { | 144 void retainWhere(bool test(E element)) { |
| 145 IterableMixinWorkaround.removeWhereList(this, | 145 IterableMixinWorkaround.removeWhereList(this, |
| 146 (E element) => !test(element)); | 146 (E element) => !test(element)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 Iterable<E> where(bool f(E element)) { | 149 Iterable<E> where(bool f(E element)) { |
| 150 return IterableMixinWorkaround.where(this, f); | 150 return new IterableMixinWorkaround<E>().where(this, f); |
| 151 } | 151 } |
| 152 | 152 |
| 153 Iterable expand(Iterable f(E element)) { | 153 Iterable expand(Iterable f(E element)) { |
| 154 return IterableMixinWorkaround.expand(this, f); | 154 return IterableMixinWorkaround.expand(this, f); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void addAll(Iterable<E> collection) { | 157 void addAll(Iterable<E> collection) { |
| 158 for (E e in collection) { | 158 for (E e in collection) { |
| 159 this.add(e); | 159 this.add(e); |
| 160 } | 160 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 174 | 174 |
| 175 String join([String separator = ""]) { | 175 String join([String separator = ""]) { |
| 176 var list = new List(this.length); | 176 var list = new List(this.length); |
| 177 for (int i = 0; i < this.length; i++) { | 177 for (int i = 0; i < this.length; i++) { |
| 178 list[i] = "${this[i]}"; | 178 list[i] = "${this[i]}"; |
| 179 } | 179 } |
| 180 return JS('String', "#.join(#)", list, separator); | 180 return JS('String', "#.join(#)", list, separator); |
| 181 } | 181 } |
| 182 | 182 |
| 183 Iterable<E> take(int n) { | 183 Iterable<E> take(int n) { |
| 184 return IterableMixinWorkaround.takeList(this, n); | 184 return new IterableMixinWorkaround<E>().takeList(this, n); |
| 185 } | 185 } |
| 186 | 186 |
| 187 Iterable<E> takeWhile(bool test(E value)) { | 187 Iterable<E> takeWhile(bool test(E value)) { |
| 188 return IterableMixinWorkaround.takeWhile(this, test); | 188 return new IterableMixinWorkaround<E>().takeWhile(this, test); |
| 189 } | 189 } |
| 190 | 190 |
| 191 Iterable<E> skip(int n) { | 191 Iterable<E> skip(int n) { |
| 192 return IterableMixinWorkaround.skipList(this, n); | 192 return new IterableMixinWorkaround<E>().skipList(this, n); |
| 193 } | 193 } |
| 194 | 194 |
| 195 Iterable<E> skipWhile(bool test(E value)) { | 195 Iterable<E> skipWhile(bool test(E value)) { |
| 196 return IterableMixinWorkaround.skipWhile(this, test); | 196 return new IterableMixinWorkaround<E>().skipWhile(this, test); |
| 197 } | 197 } |
| 198 | 198 |
| 199 E reduce(E combine(E value, E element)) { | 199 E reduce(E combine(E value, E element)) { |
| 200 return IterableMixinWorkaround.reduce(this, combine); | 200 return IterableMixinWorkaround.reduce(this, combine); |
| 201 } | 201 } |
| 202 | 202 |
| 203 fold(initialValue, combine(previousValue, E element)) { | 203 fold(initialValue, combine(previousValue, E element)) { |
| 204 return IterableMixinWorkaround.fold(this, initialValue, combine); | 204 return IterableMixinWorkaround.fold(this, initialValue, combine); |
| 205 } | 205 } |
| 206 | 206 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 234 throw new RangeError.range(end, start, length); | 234 throw new RangeError.range(end, start, length); |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 if (start == end) return <E>[]; | 237 if (start == end) return <E>[]; |
| 238 return new JSArray<E>.markGrowable( | 238 return new JSArray<E>.markGrowable( |
| 239 JS('', r'#.slice(#, #)', this, start, end)); | 239 JS('', r'#.slice(#, #)', this, start, end)); |
| 240 } | 240 } |
| 241 | 241 |
| 242 | 242 |
| 243 Iterable<E> getRange(int start, int end) { | 243 Iterable<E> getRange(int start, int end) { |
| 244 return IterableMixinWorkaround.getRangeList(this, start, end); | 244 return new IterableMixinWorkaround<E>().getRangeList(this, start, end); |
| 245 } | 245 } |
| 246 | 246 |
| 247 E get first { | 247 E get first { |
| 248 if (length > 0) return this[0]; | 248 if (length > 0) return this[0]; |
| 249 throw new StateError("No elements"); | 249 throw new StateError("No elements"); |
| 250 } | 250 } |
| 251 | 251 |
| 252 E get last { | 252 E get last { |
| 253 if (length > 0) return this[length - 1]; | 253 if (length > 0) return this[length - 1]; |
| 254 throw new StateError("No elements"); | 254 throw new StateError("No elements"); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 289 |
| 290 void replaceRange(int start, int end, Iterable<E> iterable) { | 290 void replaceRange(int start, int end, Iterable<E> iterable) { |
| 291 checkGrowable('removeRange'); | 291 checkGrowable('removeRange'); |
| 292 IterableMixinWorkaround.replaceRangeList(this, start, end, iterable); | 292 IterableMixinWorkaround.replaceRangeList(this, start, end, iterable); |
| 293 } | 293 } |
| 294 | 294 |
| 295 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f); | 295 bool any(bool f(E element)) => IterableMixinWorkaround.any(this, f); |
| 296 | 296 |
| 297 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f); | 297 bool every(bool f(E element)) => IterableMixinWorkaround.every(this, f); |
| 298 | 298 |
| 299 Iterable<E> get reversed => IterableMixinWorkaround.reversedList(this); | 299 Iterable<E> get reversed => |
| 300 new IterableMixinWorkaround<E>().reversedList(this); |
| 300 | 301 |
| 301 void sort([int compare(E a, E b)]) { | 302 void sort([int compare(E a, E b)]) { |
| 302 checkMutable('sort'); | 303 checkMutable('sort'); |
| 303 IterableMixinWorkaround.sortList(this, compare); | 304 IterableMixinWorkaround.sortList(this, compare); |
| 304 } | 305 } |
| 305 | 306 |
| 306 void shuffle([Random random]) { | 307 void shuffle([Random random]) { |
| 307 IterableMixinWorkaround.shuffleList(this, random); | 308 IterableMixinWorkaround.shuffleList(this, random); |
| 308 } | 309 } |
| 309 | 310 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 359 } |
| 359 | 360 |
| 360 void operator []=(int index, E value) { | 361 void operator []=(int index, E value) { |
| 361 checkMutable('indexed set'); | 362 checkMutable('indexed set'); |
| 362 if (index is !int) throw new ArgumentError(index); | 363 if (index is !int) throw new ArgumentError(index); |
| 363 if (index >= length || index < 0) throw new RangeError.value(index); | 364 if (index >= length || index < 0) throw new RangeError.value(index); |
| 364 JS('void', r'#[#] = #', this, index, value); | 365 JS('void', r'#[#] = #', this, index, value); |
| 365 } | 366 } |
| 366 | 367 |
| 367 Map<int, E> asMap() { | 368 Map<int, E> asMap() { |
| 368 return IterableMixinWorkaround.asMapList(this); | 369 return new IterableMixinWorkaround<E>().asMapList(this); |
| 369 } | 370 } |
| 370 } | 371 } |
| 371 | 372 |
| 372 /** | 373 /** |
| 373 * Dummy subclasses that allow the backend to track more precise | 374 * Dummy subclasses that allow the backend to track more precise |
| 374 * information about arrays through their type. The CPA type inference | 375 * information about arrays through their type. The CPA type inference |
| 375 * relies on the fact that these classes do not override [] nor []=. | 376 * relies on the fact that these classes do not override [] nor []=. |
| 376 */ | 377 */ |
| 377 class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} | 378 class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} |
| 378 class JSFixedArray<E> extends JSMutableArray<E> {} | 379 class JSFixedArray<E> extends JSMutableArray<E> {} |
| 379 class JSExtendableArray<E> extends JSMutableArray<E> {} | 380 class JSExtendableArray<E> extends JSMutableArray<E> {} |
| OLD | NEW |