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

Side by Side Diff: runtime/lib/typed_data.dart

Issue 397243002: Make IterableMixinWorkaround using classes return correctly typed Iterables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment, Created 6 years, 5 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
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | sdk/lib/_internal/lib/js_array.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 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // patch classes for Int8List ..... Float64List and ByteData implementations. 5 // patch classes for Int8List ..... Float64List and ByteData implementations.
6 6
7 import "dart:_internal"; 7 import "dart:_internal";
8 import 'dart:math' show Random; 8 import 'dart:math' show Random;
9 9
10 patch class Int8List { 10 patch class Int8List {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 // Called directly from C code. 235 // Called directly from C code.
236 factory ByteData._view(TypedData typedData, int offsetInBytes, int length) { 236 factory ByteData._view(TypedData typedData, int offsetInBytes, int length) {
237 return new _ByteDataView(typedData, offsetInBytes, length); 237 return new _ByteDataView(typedData, offsetInBytes, length);
238 } 238 }
239 } 239 }
240 240
241 241
242 // Based class for _TypedList that provides common methods for implementing 242 // Based class for _TypedList that provides common methods for implementing
243 // the collection and list interfaces. 243 // the collection and list interfaces.
244 244 // TODO(13647): Make this extends ListBase<T>
245 abstract class _TypedListBase { 245 abstract class _TypedListBase {
246 246
247 // Method(s) implementing the Collection interface. 247 // Method(s) implementing the Collection interface.
248 bool contains(element) => IterableMixinWorkaround.contains(this, element); 248 bool contains(element) => IterableMixinWorkaround.contains(this, element);
249 249
250 void forEach(void f(element)) { 250 void forEach(void f(element)) {
251 var len = this.length; 251 var len = this.length;
252 for (var i = 0; i < len; i++) { 252 for (var i = 0; i < len; i++) {
253 f(this[i]); 253 f(this[i]);
254 } 254 }
255 } 255 }
256 256
257 Iterable map(f(element)) {
258 return IterableMixinWorkaround.mapList(this, f);
259 }
260
261 String join([String separator = ""]) { 257 String join([String separator = ""]) {
262 return IterableMixinWorkaround.join(this, separator); 258 return IterableMixinWorkaround.join(this, separator);
263 } 259 }
264 260
265 dynamic reduce(dynamic combine(value, element)) { 261 dynamic reduce(dynamic combine(value, element)) {
266 return IterableMixinWorkaround.reduce(this, combine); 262 return IterableMixinWorkaround.reduce(this, combine);
267 } 263 }
268 264
269 dynamic fold(dynamic initialValue, 265 dynamic fold(dynamic initialValue,
270 dynamic combine(dynamic initialValue, element)) { 266 dynamic combine(dynamic initialValue, element)) {
271 return IterableMixinWorkaround.fold(this, initialValue, combine); 267 return IterableMixinWorkaround.fold(this, initialValue, combine);
272 } 268 }
273 269
274 Iterable where(bool f(element)) { 270 Iterable map(f(element)) {
275 return IterableMixinWorkaround.where(this, f); 271 return IterableMixinWorkaround.mapList(this, f);
276 } 272 }
277 273
278 Iterable expand(Iterable f(element)) { 274 Iterable expand(Iterable f(element)) {
279 return IterableMixinWorkaround.expand(this, f); 275 return IterableMixinWorkaround.expand(this, f);
280 } 276 }
281 277
278 // The following methods need to know the element type (int or double).
279 Iterable where(bool f(element)) {
280 return new IterableMixinWorkaround().where(this, f);
281 }
282
282 Iterable take(int n) { 283 Iterable take(int n) {
283 return IterableMixinWorkaround.takeList(this, n); 284 return new IterableMixinWorkaround().takeList(this, n);
284 } 285 }
285 286
286 Iterable takeWhile(bool test(element)) { 287 Iterable takeWhile(bool test(element)) {
287 return IterableMixinWorkaround.takeWhile(this, test); 288 return new IterableMixinWorkaround().takeWhile(this, test);
288 } 289 }
289 290
290 Iterable skip(int n) { 291 Iterable skip(int n) {
291 return IterableMixinWorkaround.skipList(this, n); 292 return new IterableMixinWorkaround().skipList(this, n);
292 } 293 }
293 294
294 Iterable skipWhile(bool test(element)) { 295 Iterable skipWhile(bool test(element)) {
295 return IterableMixinWorkaround.skipWhile(this, test); 296 return new IterableMixinWorkaround().skipWhile(this, test);
296 } 297 }
297 298
299 Iterable<dynamic> get reversed {
300 return new IterableMixinWorkaround().reversedList(this);
301 }
302
303 Map<int, dynamic> asMap() {
304 return new IterableMixinWorkaround().asMapList(this);
305 }
306
307 Iterable getRange(int start, [int end]) {
308 return new IterableMixinWorkaround().getRangeList(this, start, end);
309 }
310 // End of methods returning incorrectly parameterized types.
311
298 bool every(bool f(element)) { 312 bool every(bool f(element)) {
299 return IterableMixinWorkaround.every(this, f); 313 return IterableMixinWorkaround.every(this, f);
300 } 314 }
301 315
302 bool any(bool f(element)) { 316 bool any(bool f(element)) {
303 return IterableMixinWorkaround.any(this, f); 317 return IterableMixinWorkaround.any(this, f);
304 } 318 }
305 319
306 dynamic firstWhere(bool test(element), {orElse()}) { 320 dynamic firstWhere(bool test(element), {orElse()}) {
307 return IterableMixinWorkaround.firstWhere(this, test, orElse); 321 return IterableMixinWorkaround.firstWhere(this, test, orElse);
308 } 322 }
309 323
310 dynamic lastWhere(bool test(element), {orElse()}) { 324 dynamic lastWhere(bool test(element), {orElse()}) {
311 return IterableMixinWorkaround.lastWhereList(this, test, orElse); 325 return IterableMixinWorkaround.lastWhereList(this, test, orElse);
312 } 326 }
313 327
314 dynamic singleWhere(bool test(element)) { 328 dynamic singleWhere(bool test(element)) {
315 return IterableMixinWorkaround.singleWhere(this, test); 329 return IterableMixinWorkaround.singleWhere(this, test);
316 } 330 }
317 331
318 Iterable<dynamic> get reversed {
319 return IterableMixinWorkaround.reversedList(this);
320 }
321
322 dynamic elementAt(int index) { 332 dynamic elementAt(int index) {
323 return this[index]; 333 return this[index];
324 } 334 }
325 335
326 bool get isEmpty { 336 bool get isEmpty {
327 return this.length == 0; 337 return this.length == 0;
328 } 338 }
329 339
330 bool get isNotEmpty => !isEmpty; 340 bool get isNotEmpty => !isEmpty;
331 341
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 } 439 }
430 440
431 List toList({bool growable: true}) { 441 List toList({bool growable: true}) {
432 return new List.from(this, growable: growable); 442 return new List.from(this, growable: growable);
433 } 443 }
434 444
435 Set toSet() { 445 Set toSet() {
436 return new Set.from(this); 446 return new Set.from(this);
437 } 447 }
438 448
439 Map<int, dynamic> asMap() {
440 return IterableMixinWorkaround.asMapList(this);
441 }
442
443 List sublist(int start, [int end]) { 449 List sublist(int start, [int end]) {
444 if (end == null) end = this.length; 450 if (end == null) end = this.length;
445 int length = end - start; 451 int length = end - start;
446 _rangeCheck(this.length, start, length); 452 _rangeCheck(this.length, start, length);
447 List result = _createList(length); 453 List result = _createList(length);
448 result.setRange(0, length, this, start); 454 result.setRange(0, length, this, start);
449 return result; 455 return result;
450 } 456 }
451 457
452 Iterable getRange(int start, [int end]) {
453 return IterableMixinWorkaround.getRangeList(this, start, end);
454 }
455
456 void setRange(int start, int end, Iterable from, [int skipCount = 0]) { 458 void setRange(int start, int end, Iterable from, [int skipCount = 0]) {
457 // Check ranges. 459 // Check ranges.
458 if ((start < 0) || (start > length)) { 460 if ((start < 0) || (start > length)) {
459 _throwRangeError(start, length + 1); 461 _throwRangeError(start, length + 1);
460 } 462 }
461 if ((end < 0) || (end > length)) { 463 if ((end < 0) || (end > length)) {
462 _throwRangeError(end, length + 1); 464 _throwRangeError(end, length + 1);
463 } 465 }
464 if (start > end) { 466 if (start > end) {
465 _throwRangeError(start, end + 1); 467 _throwRangeError(start, end + 1);
(...skipping 3093 matching lines...) Expand 10 before | Expand all | Expand 10 after
3559 return value; 3561 return value;
3560 } 3562 }
3561 return object; 3563 return object;
3562 } 3564 }
3563 3565
3564 3566
3565 void _throwRangeError(int index, int length) { 3567 void _throwRangeError(int index, int length) {
3566 String message = "$index must be in the range [0..$length)"; 3568 String message = "$index must be in the range [0..$length)";
3567 throw new RangeError(message); 3569 throw new RangeError(message);
3568 } 3570 }
OLDNEW
« no previous file with comments | « runtime/lib/growable_array.dart ('k') | sdk/lib/_internal/lib/js_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698