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

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

Issue 12817003: Change getRange to sublist. Make getRange deprecated. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 void removeRange(int start, int length) { 70 void removeRange(int start, int length) {
71 throw new UnsupportedError( 71 throw new UnsupportedError(
72 "Cannot remove range of a non-extendable array"); 72 "Cannot remove range of a non-extendable array");
73 } 73 }
74 74
75 void insertRange(int start, int length, [E initialValue = null]) { 75 void insertRange(int start, int length, [E initialValue = null]) {
76 throw new UnsupportedError( 76 throw new UnsupportedError(
77 "Cannot insert range in a non-extendable array"); 77 "Cannot insert range in a non-extendable array");
78 } 78 }
79 79
80 List<E> getRange(int start, int length) { 80
81 if (length == 0) return []; 81 List<E> sublist(int start, [int end]) {
82 Arrays.rangeCheck(this, start, length); 82 Arrays.indicesCheck(this, start, end);
floitsch 2013/03/14 15:46:06 I would make this an IterableMixinWorkaround metho
Lasse Reichstein Nielsen 2013/03/15 09:13:09 It would not be a method on a mixin when we get mi
83 if (end == null) end = this.length;
84 int length = end - start;
85 if (start == end) return [];
83 List list = new _GrowableObjectArray<E>.withCapacity(length); 86 List list = new _GrowableObjectArray<E>.withCapacity(length);
84 list.length = length; 87 list.length = length;
85 Arrays.copy(this, start, list, 0, length); 88 Arrays.copy(this, start, list, 0, length);
86 return list; 89 return list;
87 } 90 }
88 91
92 List<E> getRange(int start, int length) => sublist(start, start + length);
93
89 // Iterable interface. 94 // Iterable interface.
90 95
91 bool contains(E element) { 96 bool contains(E element) {
92 return IterableMixinWorkaround.contains(this, element); 97 return IterableMixinWorkaround.contains(this, element);
93 } 98 }
94 99
95 void forEach(f(E element)) { 100 void forEach(f(E element)) {
96 IterableMixinWorkaround.forEach(this, f); 101 IterableMixinWorkaround.forEach(this, f);
97 } 102 }
98 103
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 void removeRange(int start, int length) { 313 void removeRange(int start, int length) {
309 throw new UnsupportedError( 314 throw new UnsupportedError(
310 "Cannot remove range of an immutable array"); 315 "Cannot remove range of an immutable array");
311 } 316 }
312 317
313 void insertRange(int start, int length, [E initialValue = null]) { 318 void insertRange(int start, int length, [E initialValue = null]) {
314 throw new UnsupportedError( 319 throw new UnsupportedError(
315 "Cannot insert range in an immutable array"); 320 "Cannot insert range in an immutable array");
316 } 321 }
317 322
318 List<E> getRange(int start, int length) { 323 List<E> sublist(int start, [int end]) {
319 if (length == 0) return []; 324 Arrays.indicesCheck(this, start, end);
320 Arrays.rangeCheck(this, start, length); 325 if (end == null) end = this.length;
326 int length = end - start;
327 if (start == end) return [];
321 List list = new List<E>(); 328 List list = new List<E>();
322 list.length = length; 329 list.length = length;
323 Arrays.copy(this, start, list, 0, length); 330 Arrays.copy(this, start, list, 0, length);
324 return list; 331 return list;
325 } 332 }
326 333
334 List<E> getRange(int start, int length) => sublist(start, start + length);
335
327 // Collection interface. 336 // Collection interface.
328 337
329 bool contains(E element) { 338 bool contains(E element) {
330 return IterableMixinWorkaround.contains(this, element); 339 return IterableMixinWorkaround.contains(this, element);
331 } 340 }
332 341
333 void forEach(f(E element)) { 342 void forEach(f(E element)) {
334 IterableMixinWorkaround.forEach(this, f); 343 IterableMixinWorkaround.forEach(this, f);
335 } 344 }
336 345
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 515 }
507 _position = _length; 516 _position = _length;
508 _current = null; 517 _current = null;
509 return false; 518 return false;
510 } 519 }
511 520
512 E get current { 521 E get current {
513 return _current; 522 return _current;
514 } 523 }
515 } 524 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698