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

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

Issue 107333003: Fix an old TODO. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 | « no previous file | runtime/lib/growable_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) 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 static final int _classId = (new _List(0))._cid; 8 static final int _classId = (new _List(0))._cid;
9 9
10 factory _List(length) native "List_allocate"; 10 factory _List(length) native "List_allocate";
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (end < start || end > this.length) { 71 if (end < start || end > this.length) {
72 throw new RangeError.range(end, start, this.length); 72 throw new RangeError.range(end, start, this.length);
73 } 73 }
74 int length = end - start; 74 int length = end - start;
75 if (length == 0) return; 75 if (length == 0) return;
76 76
77 if (iterable is _List) { 77 if (iterable is _List) {
78 _copyFromObjectArray(iterable, skipCount, start, length); 78 _copyFromObjectArray(iterable, skipCount, start, length);
79 } else { 79 } else {
80 if (iterable is List) { 80 if (iterable is List) {
81 Arrays.copy(iterable, skipCount, this, start, length); 81 Lists.copy(iterable, skipCount, this, start, length);
82 } else { 82 } else {
83 Iterator it = iterable.iterator; 83 Iterator it = iterable.iterator;
84 while (skipCount > 0) { 84 while (skipCount > 0) {
85 if (!it.moveNext()) return; 85 if (!it.moveNext()) return;
86 skipCount--; 86 skipCount--;
87 } 87 }
88 for (int i = start; i < end; i++) { 88 for (int i = start; i < end; i++) {
89 if (!it.moveNext()) return; 89 if (!it.moveNext()) return;
90 this[i] = it.current; 90 this[i] = it.current;
91 } 91 }
92 } 92 }
93 } 93 }
94 } 94 }
95 95
96 void removeRange(int start, int end) { 96 void removeRange(int start, int end) {
97 throw new UnsupportedError( 97 throw new UnsupportedError(
98 "Cannot remove range of a non-extendable array"); 98 "Cannot remove range of a non-extendable array");
99 } 99 }
100 100
101 void replaceRange(int start, int end, Iterable<E> iterable) { 101 void replaceRange(int start, int end, Iterable<E> iterable) {
102 throw new UnsupportedError( 102 throw new UnsupportedError(
103 "Cannot remove range of a non-extendable array"); 103 "Cannot remove range of a non-extendable array");
104 } 104 }
105 105
106 void fillRange(int start, int end, [E fillValue]) { 106 void fillRange(int start, int end, [E fillValue]) {
107 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue); 107 IterableMixinWorkaround.fillRangeList(this, start, end, fillValue);
108 } 108 }
109 109
110 List<E> sublist(int start, [int end]) { 110 List<E> sublist(int start, [int end]) {
111 Arrays.indicesCheck(this, start, end); 111 Lists.indicesCheck(this, start, end);
112 if (end == null) end = this.length; 112 if (end == null) end = this.length;
113 int length = end - start; 113 int length = end - start;
114 if (start == end) return []; 114 if (start == end) return [];
115 List list = new _GrowableList<E>.withCapacity(length); 115 List list = new _GrowableList<E>.withCapacity(length);
116 list.length = length; 116 list.length = length;
117 Arrays.copy(this, start, list, 0, length); 117 Lists.copy(this, start, list, 0, length);
118 return list; 118 return list;
119 } 119 }
120 120
121 // Iterable interface. 121 // Iterable interface.
122 122
123 bool contains(Object element) { 123 bool contains(Object element) {
124 return IterableMixinWorkaround.contains(this, element); 124 return IterableMixinWorkaround.contains(this, element);
125 } 125 }
126 126
127 void forEach(f(E element)) { 127 void forEach(f(E element)) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 202
203 void sort([int compare(E a, E b)]) { 203 void sort([int compare(E a, E b)]) {
204 IterableMixinWorkaround.sortList(this, compare); 204 IterableMixinWorkaround.sortList(this, compare);
205 } 205 }
206 206
207 void shuffle([Random random]) { 207 void shuffle([Random random]) {
208 IterableMixinWorkaround.shuffleList(this, random); 208 IterableMixinWorkaround.shuffleList(this, random);
209 } 209 }
210 210
211 int indexOf(Object element, [int start = 0]) { 211 int indexOf(Object element, [int start = 0]) {
212 return Arrays.indexOf(this, element, start, this.length); 212 return Lists.indexOf(this, element, start, this.length);
213 } 213 }
214 214
215 int lastIndexOf(Object element, [int start = null]) { 215 int lastIndexOf(Object element, [int start = null]) {
216 if (start == null) start = length - 1; 216 if (start == null) start = length - 1;
217 return Arrays.lastIndexOf(this, element, start); 217 return Lists.lastIndexOf(this, element, start);
218 } 218 }
219 219
220 Iterator<E> get iterator { 220 Iterator<E> get iterator {
221 return new _FixedSizeArrayIterator<E>(this); 221 return new _FixedSizeArrayIterator<E>(this);
222 } 222 }
223 223
224 void add(E element) { 224 void add(E element) {
225 throw new UnsupportedError( 225 throw new UnsupportedError(
226 "Cannot add to a non-extendable array"); 226 "Cannot add to a non-extendable array");
227 } 227 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 throw new UnsupportedError( 354 throw new UnsupportedError(
355 "Cannot modify an immutable array"); 355 "Cannot modify an immutable array");
356 } 356 }
357 357
358 void replaceRange(int start, int end, Iterable<E> iterable) { 358 void replaceRange(int start, int end, Iterable<E> iterable) {
359 throw new UnsupportedError( 359 throw new UnsupportedError(
360 "Cannot modify an immutable array"); 360 "Cannot modify an immutable array");
361 } 361 }
362 362
363 List<E> sublist(int start, [int end]) { 363 List<E> sublist(int start, [int end]) {
364 Arrays.indicesCheck(this, start, end); 364 Lists.indicesCheck(this, start, end);
365 if (end == null) end = this.length; 365 if (end == null) end = this.length;
366 int length = end - start; 366 int length = end - start;
367 if (start == end) return []; 367 if (start == end) return [];
368 List list = new List<E>(); 368 List list = new List<E>();
369 list.length = length; 369 list.length = length;
370 Arrays.copy(this, start, list, 0, length); 370 Lists.copy(this, start, list, 0, length);
371 return list; 371 return list;
372 } 372 }
373 373
374 Iterable<E> getRange(int start, int end) { 374 Iterable<E> getRange(int start, int end) {
375 return IterableMixinWorkaround.getRangeList(this, start, end); 375 return IterableMixinWorkaround.getRangeList(this, start, end);
376 } 376 }
377 377
378 // Collection interface. 378 // Collection interface.
379 379
380 bool contains(Object element) { 380 bool contains(Object element) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 void shuffle([Random random]) { 465 void shuffle([Random random]) {
466 throw new UnsupportedError( 466 throw new UnsupportedError(
467 "Cannot modify an immutable array"); 467 "Cannot modify an immutable array");
468 } 468 }
469 469
470 String toString() { 470 String toString() {
471 return IterableMixinWorkaround.toStringIterable(this, '[', ']'); 471 return IterableMixinWorkaround.toStringIterable(this, '[', ']');
472 } 472 }
473 473
474 int indexOf(Object element, [int start = 0]) { 474 int indexOf(Object element, [int start = 0]) {
475 return Arrays.indexOf(this, element, start, this.length); 475 return Lists.indexOf(this, element, start, this.length);
476 } 476 }
477 477
478 int lastIndexOf(Object element, [int start = null]) { 478 int lastIndexOf(Object element, [int start = null]) {
479 if (start == null) start = length - 1; 479 if (start == null) start = length - 1;
480 return Arrays.lastIndexOf(this, element, start); 480 return Lists.lastIndexOf(this, element, start);
481 } 481 }
482 482
483 Iterator<E> get iterator { 483 Iterator<E> get iterator {
484 return new _FixedSizeArrayIterator<E>(this); 484 return new _FixedSizeArrayIterator<E>(this);
485 } 485 }
486 486
487 void add(E element) { 487 void add(E element) {
488 throw new UnsupportedError( 488 throw new UnsupportedError(
489 "Cannot add to an immutable array"); 489 "Cannot add to an immutable array");
490 } 490 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 } 560 }
561 _position = _length; 561 _position = _length;
562 _current = null; 562 _current = null;
563 return false; 563 return false;
564 } 564 }
565 565
566 E get current { 566 E get current {
567 return _current; 567 return _current;
568 } 568 }
569 } 569 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/growable_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698