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

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: Address comments. 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 Arrays.indicesCheck(this, start, end); 332 Arrays.indicesCheck(this, start, end);
331 if (end == null) end = this.length; 333 if (end == null) end = this.length;
332 int length = end - start; 334 int length = end - start;
333 if (start == end) return []; 335 if (start == end) return [];
334 List list = new List<E>(); 336 List list = new List<E>();
335 list.length = length; 337 list.length = length;
336 Arrays.copy(this, start, list, 0, length); 338 Arrays.copy(this, start, list, 0, length);
337 return list; 339 return list;
338 } 340 }
339 341
340 List<E> getRange(int start, int length) => sublist(start, start + length); 342 Iterable<E> getRange(int start, int end) {
343 return IterableMixinWorkaround.getRangeList(this, start, end);
344 }
341 345
342 // Collection interface. 346 // Collection interface.
343 347
344 bool contains(E element) { 348 bool contains(E element) {
345 return IterableMixinWorkaround.contains(this, element); 349 return IterableMixinWorkaround.contains(this, element);
346 } 350 }
347 351
348 void forEach(f(E element)) { 352 void forEach(f(E element)) {
349 IterableMixinWorkaround.forEach(this, f); 353 IterableMixinWorkaround.forEach(this, f);
350 } 354 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 } 521 }
518 _position = _length; 522 _position = _length;
519 _current = null; 523 _current = null;
520 return false; 524 return false;
521 } 525 }
522 526
523 E get current { 527 E get current {
524 return _current; 528 return _current;
525 } 529 }
526 } 530 }
OLDNEW
« no previous file with comments | « editor/util/plugins/com.google.dart.java2dart/resources/java_core.dart ('k') | runtime/lib/growable_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698