| 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 | 5 |
| 6 // TODO(srdjan): Use shared array implementation. | 6 // TODO(srdjan): Use shared array implementation. |
| 7 class _List<E> implements List<E> { | 7 class _List<E> implements List<E> { |
| 8 | 8 |
| 9 factory _List(length) native "List_allocate"; | 9 factory _List(length) native "List_allocate"; |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 void removeWhere(bool test(E element)) { | 47 void removeWhere(bool test(E element)) { |
| 48 throw NonGrowableListError.remove(); | 48 throw NonGrowableListError.remove(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void retainWhere(bool test(E element)) { | 51 void retainWhere(bool test(E element)) { |
| 52 throw NonGrowableListError.remove(); | 52 throw NonGrowableListError.remove(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 Iterable<E> getRange(int start, [int end]) { | 55 Iterable<E> getRange(int start, [int end]) { |
| 56 return IterableMixinWorkaround.getRangeList(this, start, end); | 56 return new IterableMixinWorkaround<E>().getRangeList(this, start, end); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // List interface. | 59 // List interface. |
| 60 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { | 60 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { |
| 61 if (start < 0 || start > this.length) { | 61 if (start < 0 || start > this.length) { |
| 62 throw new RangeError.range(start, 0, this.length); | 62 throw new RangeError.range(start, 0, this.length); |
| 63 } | 63 } |
| 64 if (end < start || end > this.length) { | 64 if (end < start || end > this.length) { |
| 65 throw new RangeError.range(end, start, this.length); | 65 throw new RangeError.range(end, start, this.length); |
| 66 } | 66 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 E reduce(E combine(E value, E element)) { | 130 E reduce(E combine(E value, E element)) { |
| 131 return IterableMixinWorkaround.reduce(this, combine); | 131 return IterableMixinWorkaround.reduce(this, combine); |
| 132 } | 132 } |
| 133 | 133 |
| 134 fold(initialValue, combine(previousValue, E element)) { | 134 fold(initialValue, combine(previousValue, E element)) { |
| 135 return IterableMixinWorkaround.fold(this, initialValue, combine); | 135 return IterableMixinWorkaround.fold(this, initialValue, combine); |
| 136 } | 136 } |
| 137 | 137 |
| 138 Iterable<E> where(bool f(E element)) { | 138 Iterable<E> where(bool f(E element)) { |
| 139 return IterableMixinWorkaround.where(this, f); | 139 return new IterableMixinWorkaround<E>().where(this, f); |
| 140 } | 140 } |
| 141 | 141 |
| 142 Iterable expand(Iterable f(E element)) { | 142 Iterable expand(Iterable f(E element)) { |
| 143 return IterableMixinWorkaround.expand(this, f); | 143 return IterableMixinWorkaround.expand(this, f); |
| 144 } | 144 } |
| 145 | 145 |
| 146 Iterable<E> take(int n) { | 146 Iterable<E> take(int n) { |
| 147 return IterableMixinWorkaround.takeList(this, n); | 147 return new IterableMixinWorkaround<E>().takeList(this, n); |
| 148 } | 148 } |
| 149 | 149 |
| 150 Iterable<E> takeWhile(bool test(E value)) { | 150 Iterable<E> takeWhile(bool test(E value)) { |
| 151 return IterableMixinWorkaround.takeWhile(this, test); | 151 return new IterableMixinWorkaround<E>().takeWhile(this, test); |
| 152 } | 152 } |
| 153 | 153 |
| 154 Iterable<E> skip(int n) { | 154 Iterable<E> skip(int n) { |
| 155 return IterableMixinWorkaround.skipList(this, n); | 155 return new IterableMixinWorkaround<E>().skipList(this, n); |
| 156 } | 156 } |
| 157 | 157 |
| 158 Iterable<E> skipWhile(bool test(E value)) { | 158 Iterable<E> skipWhile(bool test(E value)) { |
| 159 return IterableMixinWorkaround.skipWhile(this, test); | 159 return new IterableMixinWorkaround<E>().skipWhile(this, test); |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool every(bool f(E element)) { | 162 bool every(bool f(E element)) { |
| 163 return IterableMixinWorkaround.every(this, f); | 163 return IterableMixinWorkaround.every(this, f); |
| 164 } | 164 } |
| 165 | 165 |
| 166 bool any(bool f(E element)) { | 166 bool any(bool f(E element)) { |
| 167 return IterableMixinWorkaround.any(this, f); | 167 return IterableMixinWorkaround.any(this, f); |
| 168 } | 168 } |
| 169 | 169 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 182 E elementAt(int index) { | 182 E elementAt(int index) { |
| 183 return this[index]; | 183 return this[index]; |
| 184 } | 184 } |
| 185 | 185 |
| 186 bool get isEmpty { | 186 bool get isEmpty { |
| 187 return this.length == 0; | 187 return this.length == 0; |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool get isNotEmpty => !isEmpty; | 190 bool get isNotEmpty => !isEmpty; |
| 191 | 191 |
| 192 Iterable<E> get reversed => IterableMixinWorkaround.reversedList(this); | 192 Iterable<E> get reversed => |
| 193 new IterableMixinWorkaround<E>().reversedList(this); |
| 193 | 194 |
| 194 void sort([int compare(E a, E b)]) { | 195 void sort([int compare(E a, E b)]) { |
| 195 IterableMixinWorkaround.sortList(this, compare); | 196 IterableMixinWorkaround.sortList(this, compare); |
| 196 } | 197 } |
| 197 | 198 |
| 198 void shuffle([Random random]) { | 199 void shuffle([Random random]) { |
| 199 IterableMixinWorkaround.shuffleList(this, random); | 200 IterableMixinWorkaround.shuffleList(this, random); |
| 200 } | 201 } |
| 201 | 202 |
| 202 int indexOf(Object element, [int start = 0]) { | 203 int indexOf(Object element, [int start = 0]) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 251 |
| 251 List<E> toList({ bool growable: true}) { | 252 List<E> toList({ bool growable: true}) { |
| 252 return new List<E>.from(this, growable: growable); | 253 return new List<E>.from(this, growable: growable); |
| 253 } | 254 } |
| 254 | 255 |
| 255 Set<E> toSet() { | 256 Set<E> toSet() { |
| 256 return new Set<E>.from(this); | 257 return new Set<E>.from(this); |
| 257 } | 258 } |
| 258 | 259 |
| 259 Map<int, E> asMap() { | 260 Map<int, E> asMap() { |
| 260 return IterableMixinWorkaround.asMapList(this); | 261 return new IterableMixinWorkaround<E>().asMapList(this); |
| 261 } | 262 } |
| 262 } | 263 } |
| 263 | 264 |
| 264 | 265 |
| 265 // This is essentially the same class as _List, but it does not | 266 // This is essentially the same class as _List, but it does not |
| 266 // permit any modification of array elements from Dart code. We use | 267 // permit any modification of array elements from Dart code. We use |
| 267 // this class for arrays constructed from Dart array literals. | 268 // this class for arrays constructed from Dart array literals. |
| 268 // TODO(hausner): We should consider the trade-offs between two | 269 // TODO(hausner): We should consider the trade-offs between two |
| 269 // classes (and inline cache misses) versus a field in the native | 270 // classes (and inline cache misses) versus a field in the native |
| 270 // implementation (checks when modifying). We should keep watching | 271 // implementation (checks when modifying). We should keep watching |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 if (end == null) end = this.length; | 341 if (end == null) end = this.length; |
| 341 int length = end - start; | 342 int length = end - start; |
| 342 if (start == end) return []; | 343 if (start == end) return []; |
| 343 List list = new List<E>(); | 344 List list = new List<E>(); |
| 344 list.length = length; | 345 list.length = length; |
| 345 Lists.copy(this, start, list, 0, length); | 346 Lists.copy(this, start, list, 0, length); |
| 346 return list; | 347 return list; |
| 347 } | 348 } |
| 348 | 349 |
| 349 Iterable<E> getRange(int start, int end) { | 350 Iterable<E> getRange(int start, int end) { |
| 350 return IterableMixinWorkaround.getRangeList(this, start, end); | 351 return new IterableMixinWorkaround<E>().getRangeList(this, start, end); |
| 351 } | 352 } |
| 352 | 353 |
| 353 // Collection interface. | 354 // Collection interface. |
| 354 | 355 |
| 355 bool contains(Object element) { | 356 bool contains(Object element) { |
| 356 return IterableMixinWorkaround.contains(this, element); | 357 return IterableMixinWorkaround.contains(this, element); |
| 357 } | 358 } |
| 358 | 359 |
| 359 void forEach(f(E element)) { | 360 void forEach(f(E element)) { |
| 360 IterableMixinWorkaround.forEach(this, f); | 361 IterableMixinWorkaround.forEach(this, f); |
| 361 } | 362 } |
| 362 | 363 |
| 363 Iterable map(f(E element)) { | 364 Iterable map(f(E element)) { |
| 364 return IterableMixinWorkaround.mapList(this, f); | 365 return IterableMixinWorkaround.mapList(this, f); |
| 365 } | 366 } |
| 366 | 367 |
| 367 String join([String separator = ""]) { | 368 String join([String separator = ""]) { |
| 368 return IterableMixinWorkaround.joinList(this, separator); | 369 return IterableMixinWorkaround.joinList(this, separator); |
| 369 } | 370 } |
| 370 | 371 |
| 371 E reduce(E combine(E value, E element)) { | 372 E reduce(E combine(E value, E element)) { |
| 372 return IterableMixinWorkaround.reduce(this, combine); | 373 return IterableMixinWorkaround.reduce(this, combine); |
| 373 } | 374 } |
| 374 | 375 |
| 375 fold(initialValue, combine(previousValue, E element)) { | 376 fold(initialValue, combine(previousValue, E element)) { |
| 376 return IterableMixinWorkaround.fold(this, initialValue, combine); | 377 return IterableMixinWorkaround.fold(this, initialValue, combine); |
| 377 } | 378 } |
| 378 | 379 |
| 379 Iterable<E> where(bool f(E element)) { | 380 Iterable<E> where(bool f(E element)) { |
| 380 return IterableMixinWorkaround.where(this, f); | 381 return new IterableMixinWorkaround<E>().where(this, f); |
| 381 } | 382 } |
| 382 | 383 |
| 383 Iterable expand(Iterable f(E element)) { | 384 Iterable expand(Iterable f(E element)) { |
| 384 return IterableMixinWorkaround.expand(this, f); | 385 return IterableMixinWorkaround.expand(this, f); |
| 385 } | 386 } |
| 386 | 387 |
| 387 Iterable<E> take(int n) { | 388 Iterable<E> take(int n) { |
| 388 return IterableMixinWorkaround.takeList(this, n); | 389 return new IterableMixinWorkaround<E>().takeList(this, n); |
| 389 } | 390 } |
| 390 | 391 |
| 391 Iterable<E> takeWhile(bool test(E value)) { | 392 Iterable<E> takeWhile(bool test(E value)) { |
| 392 return IterableMixinWorkaround.takeWhile(this, test); | 393 return new IterableMixinWorkaround<E>().takeWhile(this, test); |
| 393 } | 394 } |
| 394 | 395 |
| 395 Iterable<E> skip(int n) { | 396 Iterable<E> skip(int n) { |
| 396 return IterableMixinWorkaround.skipList(this, n); | 397 return new IterableMixinWorkaround<E>().skipList(this, n); |
| 397 } | 398 } |
| 398 | 399 |
| 399 Iterable<E> skipWhile(bool test(E value)) { | 400 Iterable<E> skipWhile(bool test(E value)) { |
| 400 return IterableMixinWorkaround.skipWhile(this, test); | 401 return new IterableMixinWorkaround<E>().skipWhile(this, test); |
| 401 } | 402 } |
| 402 | 403 |
| 403 bool every(bool f(E element)) { | 404 bool every(bool f(E element)) { |
| 404 return IterableMixinWorkaround.every(this, f); | 405 return IterableMixinWorkaround.every(this, f); |
| 405 } | 406 } |
| 406 | 407 |
| 407 bool any(bool f(E element)) { | 408 bool any(bool f(E element)) { |
| 408 return IterableMixinWorkaround.any(this, f); | 409 return IterableMixinWorkaround.any(this, f); |
| 409 } | 410 } |
| 410 | 411 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 423 E elementAt(int index) { | 424 E elementAt(int index) { |
| 424 return this[index]; | 425 return this[index]; |
| 425 } | 426 } |
| 426 | 427 |
| 427 bool get isEmpty { | 428 bool get isEmpty { |
| 428 return this.length == 0; | 429 return this.length == 0; |
| 429 } | 430 } |
| 430 | 431 |
| 431 bool get isNotEmpty => !isEmpty; | 432 bool get isNotEmpty => !isEmpty; |
| 432 | 433 |
| 433 Iterable<E> get reversed => IterableMixinWorkaround.reversedList(this); | 434 Iterable<E> get reversed => |
| 435 new IterableMixinWorkaround<E>().reversedList(this); |
| 434 | 436 |
| 435 void sort([int compare(E a, E b)]) { | 437 void sort([int compare(E a, E b)]) { |
| 436 throw UnmodifiableListError.change(); | 438 throw UnmodifiableListError.change(); |
| 437 } | 439 } |
| 438 | 440 |
| 439 void shuffle([Random random]) { | 441 void shuffle([Random random]) { |
| 440 throw UnmodifiableListError.change(); | 442 throw UnmodifiableListError.change(); |
| 441 } | 443 } |
| 442 | 444 |
| 443 String toString() { | 445 String toString() { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 | 497 |
| 496 List<E> toList({ bool growable: true }) { | 498 List<E> toList({ bool growable: true }) { |
| 497 return new List<E>.from(this, growable: growable); | 499 return new List<E>.from(this, growable: growable); |
| 498 } | 500 } |
| 499 | 501 |
| 500 Set<E> toSet() { | 502 Set<E> toSet() { |
| 501 return new Set<E>.from(this); | 503 return new Set<E>.from(this); |
| 502 } | 504 } |
| 503 | 505 |
| 504 Map<int, E> asMap() { | 506 Map<int, E> asMap() { |
| 505 return IterableMixinWorkaround.asMapList(this); | 507 return new IterableMixinWorkaround<E>().asMapList(this); |
| 506 } | 508 } |
| 507 } | 509 } |
| 508 | 510 |
| 509 | 511 |
| 510 // Iterator for arrays with fixed size. | 512 // Iterator for arrays with fixed size. |
| 511 class _FixedSizeArrayIterator<E> implements Iterator<E> { | 513 class _FixedSizeArrayIterator<E> implements Iterator<E> { |
| 512 final List<E> _array; | 514 final List<E> _array; |
| 513 final int _length; // Cache array length for faster access. | 515 final int _length; // Cache array length for faster access. |
| 514 int _position; | 516 int _position; |
| 515 E _current; | 517 E _current; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 528 } | 530 } |
| 529 _position = _length; | 531 _position = _length; |
| 530 _current = null; | 532 _current = null; |
| 531 return false; | 533 return false; |
| 532 } | 534 } |
| 533 | 535 |
| 534 E get current { | 536 E get current { |
| 535 return _current; | 537 return _current; |
| 536 } | 538 } |
| 537 } | 539 } |
| OLD | NEW |