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

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

Issue 169963004: Fix dartbug.com/16308 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 | « no previous file | runtime/lib/typed_data.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";
11 11
12 E operator [](int index) native "List_getIndexed"; 12 E operator [](int index) native "List_getIndexed";
13 13
14 void operator []=(int index, E value) native "List_setIndexed"; 14 void operator []=(int index, E value) native "List_setIndexed";
15 15
16 String toString() { 16 String toString() {
17 return IterableMixinWorkaround.toStringIterable(this,'[' , ']'); 17 return IterableMixinWorkaround.toStringIterable(this,'[' , ']');
18 } 18 }
19 19
20 int get length native "List_getLength"; 20 int get length native "List_getLength";
21 21
22 void _copyFromObjectArray(_List src, 22 void _copyFromObjectArray(_List src,
23 int srcStart, 23 int srcStart,
24 int dstStart, 24 int dstStart,
25 int count) 25 int count)
26 native "List_copyFromObjectArray"; 26 native "List_copyFromObjectArray";
27 27
28 void insert(int index, E element) { 28 void insert(int index, E element) {
29 throw new UnsupportedError( 29 throw new UnsupportedError(
30 "Cannot add to a non-extendable array"); 30 "Cannot insert into a fixed-length list");
31 } 31 }
32 32
33 void insertAll(int index, Iterable<E> iterable) { 33 void insertAll(int index, Iterable<E> iterable) {
34 throw new UnsupportedError( 34 throw new UnsupportedError(
35 "Cannot add to a non-extendable array"); 35 "Cannot insert into a fixed-length list");
36 } 36 }
37 37
38 void setAll(int index, Iterable<E> iterable) { 38 void setAll(int index, Iterable<E> iterable) {
39 IterableMixinWorkaround.setAllList(this, index, iterable); 39 IterableMixinWorkaround.setAllList(this, index, iterable);
40 } 40 }
41 41
42 E removeAt(int index) { 42 E removeAt(int index) {
43 throw new UnsupportedError( 43 throw new UnsupportedError(
44 "Cannot remove element of a non-extendable array"); 44 "Cannot remove from a fixed-length list");
45 } 45 }
46 46
47 bool remove(Object element) { 47 bool remove(Object element) {
48 throw new UnsupportedError( 48 throw new UnsupportedError(
49 "Cannot remove element of a non-extendable array"); 49 "Cannot remove from a fixed-length list");
50 } 50 }
51 51
52 void removeWhere(bool test(E element)) { 52 void removeWhere(bool test(E element)) {
53 throw new UnsupportedError( 53 throw new UnsupportedError(
54 "Cannot remove element of a non-extendable array"); 54 "Cannot remove from a fixed-length list");
55 } 55 }
56 56
57 void retainWhere(bool test(E element)) { 57 void retainWhere(bool test(E element)) {
58 throw new UnsupportedError( 58 throw new UnsupportedError(
59 "Cannot remove element of a non-extendable array"); 59 "Cannot remove from a fixed-length list");
60 } 60 }
61 61
62 Iterable<E> getRange(int start, [int end]) { 62 Iterable<E> getRange(int start, [int end]) {
63 return IterableMixinWorkaround.getRangeList(this, start, end); 63 return IterableMixinWorkaround.getRangeList(this, start, end);
64 } 64 }
65 65
66 // List interface. 66 // List interface.
67 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) { 67 void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
68 if (start < 0 || start > this.length) { 68 if (start < 0 || start > this.length) {
69 throw new RangeError.range(start, 0, this.length); 69 throw new RangeError.range(start, 0, this.length);
(...skipping 18 matching lines...) Expand all
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 from a fixed-length list");
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 from a fixed-length list");
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 Lists.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;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 if (start == null) start = length - 1; 216 if (start == null) start = length - 1;
217 return Lists.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 fixed-length list");
227 } 227 }
228 228
229 void addAll(Iterable<E> iterable) { 229 void addAll(Iterable<E> iterable) {
230 throw new UnsupportedError( 230 throw new UnsupportedError(
231 "Cannot add to a non-extendable array"); 231 "Cannot add to a fixed-length list");
232 } 232 }
233 233
234 void clear() { 234 void clear() {
235 throw new UnsupportedError( 235 throw new UnsupportedError(
236 "Cannot clear a non-extendable array"); 236 "Cannot clear a fixed-length list");
237 } 237 }
238 238
239 void set length(int length) { 239 void set length(int length) {
240 throw new UnsupportedError( 240 throw new UnsupportedError(
241 "Cannot change the length of a non-extendable array"); 241 "Cannot resize a fixed-length list");
242 } 242 }
243 243
244 E removeLast() { 244 E removeLast() {
245 throw new UnsupportedError( 245 throw new UnsupportedError(
246 "Cannot remove in a non-extendable array"); 246 "Cannot remove from a fixed-length list");
247 } 247 }
248 248
249 E get first { 249 E get first {
250 if (length > 0) return this[0]; 250 if (length > 0) return this[0];
251 throw new StateError("No elements"); 251 throw new StateError("No elements");
252 } 252 }
253 253
254 E get last { 254 E get last {
255 if (length > 0) return this[length - 1]; 255 if (length > 0) return this[length - 1];
256 throw new StateError("No elements"); 256 throw new StateError("No elements");
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 "Cannot clear an immutable array"); 502 "Cannot clear an immutable array");
503 } 503 }
504 504
505 void set length(int length) { 505 void set length(int length) {
506 throw new UnsupportedError( 506 throw new UnsupportedError(
507 "Cannot change the length of an immutable array"); 507 "Cannot change the length of an immutable array");
508 } 508 }
509 509
510 E removeLast() { 510 E removeLast() {
511 throw new UnsupportedError( 511 throw new UnsupportedError(
512 "Cannot remove in a non-extendable array"); 512 "Cannot remove from a fixed-length list");
513 } 513 }
514 514
515 E get first { 515 E get first {
516 if (length > 0) return this[0]; 516 if (length > 0) return this[0];
517 throw new StateError("No elements"); 517 throw new StateError("No elements");
518 } 518 }
519 519
520 E get last { 520 E get last {
521 if (length > 0) return this[length - 1]; 521 if (length > 0) return this[length - 1];
522 throw new StateError("No elements"); 522 throw new StateError("No elements");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } 563 }
564 _position = _length; 564 _position = _length;
565 _current = null; 565 _current = null;
566 return false; 566 return false;
567 } 567 }
568 568
569 E get current { 569 E get current {
570 return _current; 570 return _current;
571 } 571 }
572 } 572 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/typed_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698