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

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

Issue 14065011: Implement getRange (returning an Iterable). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes and status-file update. Created 7 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 | Annotate | Revision Log
OLDNEW
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 _ObjectArray<E> implements List<E> { 7 class _ObjectArray<E> implements List<E> {
8 8
9 factory _ObjectArray(length) native "ObjectArray_allocate"; 9 factory _ObjectArray(length) native "ObjectArray_allocate";
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void removeWhere(bool test(E element)) { 53 void removeWhere(bool test(E element)) {
54 throw new UnsupportedError( 54 throw new UnsupportedError(
55 "Cannot remove element of a non-extendable array"); 55 "Cannot remove element of a non-extendable array");
56 } 56 }
57 57
58 void retainWhere(bool test(E element)) { 58 void retainWhere(bool test(E element)) {
59 throw new UnsupportedError( 59 throw new UnsupportedError(
60 "Cannot remove element of a non-extendable array"); 60 "Cannot remove element of a non-extendable array");
61 } 61 }
62 62
63 Iterable<E> getRange(int start, [int end]) {
64 return IterableMixinWorkaround.getRangeList(this, start, end);
65 }
66
63 // List interface. 67 // List interface.
64 void setRange(int start, int length, List<E> from, [int startFrom = 0]) { 68 void setRange(int start, int length, List<E> from, [int startFrom = 0]) {
65 if (length < 0) { 69 if (length < 0) {
66 throw new ArgumentError("negative length $length"); 70 throw new ArgumentError("negative length $length");
67 } 71 }
68 if (from is _ObjectArray) { 72 if (from is _ObjectArray) {
69 _copyFromObjectArray(from, startFrom, start, length); 73 _copyFromObjectArray(from, startFrom, start, length);
70 } else { 74 } else {
71 Arrays.copy(from, startFrom, this, start, length); 75 Arrays.copy(from, startFrom, this, start, length);
72 } 76 }
(...skipping 14 matching lines...) Expand all
87 Arrays.indicesCheck(this, start, end); 91 Arrays.indicesCheck(this, start, end);
88 if (end == null) end = this.length; 92 if (end == null) end = this.length;
89 int length = end - start; 93 int length = end - start;
90 if (start == end) return []; 94 if (start == end) return [];
91 List list = new _GrowableObjectArray<E>.withCapacity(length); 95 List list = new _GrowableObjectArray<E>.withCapacity(length);
92 list.length = length; 96 list.length = length;
93 Arrays.copy(this, start, list, 0, length); 97 Arrays.copy(this, start, list, 0, length);
94 return list; 98 return list;
95 } 99 }
96 100
97 List<E> getRange(int start, int length) => sublist(start, start + length);
98
99 // Iterable interface. 101 // Iterable interface.
100 102
101 bool contains(E element) { 103 bool contains(E element) {
102 return IterableMixinWorkaround.contains(this, element); 104 return IterableMixinWorkaround.contains(this, element);
103 } 105 }
104 106
105 void forEach(f(E element)) { 107 void forEach(f(E element)) {
106 IterableMixinWorkaround.forEach(this, f); 108 IterableMixinWorkaround.forEach(this, f);
107 } 109 }
108 110
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 Arrays.indicesCheck(this, start, end); 336 Arrays.indicesCheck(this, start, end);
335 if (end == null) end = this.length; 337 if (end == null) end = this.length;
336 int length = end - start; 338 int length = end - start;
337 if (start == end) return []; 339 if (start == end) return [];
338 List list = new List<E>(); 340 List list = new List<E>();
339 list.length = length; 341 list.length = length;
340 Arrays.copy(this, start, list, 0, length); 342 Arrays.copy(this, start, list, 0, length);
341 return list; 343 return list;
342 } 344 }
343 345
344 List<E> getRange(int start, int length) => sublist(start, start + length); 346 Iterable<E> getRange(int start, int end) {
347 return IterableMixinWorkaround.getRangeList(this, start, end);
348 }
345 349
346 // Collection interface. 350 // Collection interface.
347 351
348 bool contains(E element) { 352 bool contains(E element) {
349 return IterableMixinWorkaround.contains(this, element); 353 return IterableMixinWorkaround.contains(this, element);
350 } 354 }
351 355
352 void forEach(f(E element)) { 356 void forEach(f(E element)) {
353 IterableMixinWorkaround.forEach(this, f); 357 IterableMixinWorkaround.forEach(this, f);
354 } 358 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 } 529 }
526 _position = _length; 530 _position = _length;
527 _current = null; 531 _current = null;
528 return false; 532 return false;
529 } 533 }
530 534
531 E get current { 535 E get current {
532 return _current; 536 return _current;
533 } 537 }
534 } 538 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698