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 11416240: Address Ivan's comments. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Fix typos Created 8 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/byte_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 _ObjectArray<E> implements List<E> { 7 class _ObjectArray<E> implements List<E> {
8 8
9 factory _ObjectArray(int length) native "ObjectArray_allocate"; 9 factory _ObjectArray(int length) native "ObjectArray_allocate";
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (length == 0) return []; 54 if (length == 0) return [];
55 Arrays.rangeCheck(this, start, length); 55 Arrays.rangeCheck(this, start, length);
56 List list = new _GrowableObjectArray<E>.withCapacity(length); 56 List list = new _GrowableObjectArray<E>.withCapacity(length);
57 list.length = length; 57 list.length = length;
58 Arrays.copy(this, start, list, 0, length); 58 Arrays.copy(this, start, list, 0, length);
59 return list; 59 return list;
60 } 60 }
61 61
62 // Collection interface. 62 // Collection interface.
63 63
64 bool contains(E element) => Collections.contains(this, element); 64 bool contains(E element) {
65 return Collections.contains(this, element);
66 }
65 67
66 void forEach(f(E element)) { 68 void forEach(f(E element)) {
67 Collections.forEach(this, f); 69 Collections.forEach(this, f);
68 } 70 }
69 71
70 Iterable mappedBy(f(E element)) => new MappedIterable<E, dynamic>(this, f); 72 Iterable mappedBy(f(E element)) {
73 return new MappedIterable<E, dynamic>(this, f);
74 }
71 75
72 reduce(initialValue, combine(previousValue, E element)) { 76 reduce(initialValue, combine(previousValue, E element)) {
73 return Collections.reduce(this, initialValue, combine); 77 return Collections.reduce(this, initialValue, combine);
74 } 78 }
75 79
76 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); 80 Iterable<E> where(bool f(E element)) {
81 return new WhereIterable<E>(this, f);
82 }
77 83
78 bool every(bool f(E element)) { 84 bool every(bool f(E element)) {
79 return Collections.every(this, f); 85 return Collections.every(this, f);
80 } 86 }
81 87
82 bool any(bool f(E element)) { 88 bool any(bool f(E element)) {
83 return Collections.any(this, f); 89 return Collections.any(this, f);
84 } 90 }
85 91
86 bool get isEmpty { 92 bool get isEmpty {
87 return this.length == 0; 93 return this.length == 0;
88 } 94 }
89 95
90 void sort([Comparator<E> compare = Comparable.compare]) { 96 void sort([Comparator<E> compare = Comparable.compare]) {
91 _Sort.sort(this, compare); 97 _Sort.sort(this, compare);
92 } 98 }
93 99
94 int indexOf(E element, [int start = 0]) { 100 int indexOf(E element, [int start = 0]) {
95 return Arrays.indexOf(this, element, start, this.length); 101 return Arrays.indexOf(this, element, start, this.length);
96 } 102 }
97 103
98 int lastIndexOf(E element, [int start = null]) { 104 int lastIndexOf(E element, [int start = null]) {
99 if (start == null) start = length - 1; 105 if (start == null) start = length - 1;
100 return Arrays.lastIndexOf(this, element, start); 106 return Arrays.lastIndexOf(this, element, start);
101 } 107 }
102 108
103 Iterator<E> get iterator => new _FixedSizeArrayIterator<E>(this); 109 Iterator<E> get iterator {
110 return new _FixedSizeArrayIterator<E>(this);
111 }
104 112
105 void add(E element) { 113 void add(E element) {
106 throw new UnsupportedError( 114 throw new UnsupportedError(
107 "Cannot add to a non-extendable array"); 115 "Cannot add to a non-extendable array");
108 } 116 }
109 117
110 void addLast(E element) { 118 void addLast(E element) {
111 add(element); 119 add(element);
112 } 120 }
113 121
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 if (length == 0) return []; 209 if (length == 0) return [];
202 Arrays.rangeCheck(this, start, length); 210 Arrays.rangeCheck(this, start, length);
203 List list = new List<E>(); 211 List list = new List<E>();
204 list.length = length; 212 list.length = length;
205 Arrays.copy(this, start, list, 0, length); 213 Arrays.copy(this, start, list, 0, length);
206 return list; 214 return list;
207 } 215 }
208 216
209 // Collection interface. 217 // Collection interface.
210 218
211 bool contains(E element) => Collections.contains(this, element); 219 bool contains(E element) {
220 return Collections.contains(this, element);
221 }
212 222
213 void forEach(f(E element)) { 223 void forEach(f(E element)) {
214 Collections.forEach(this, f); 224 Collections.forEach(this, f);
215 } 225 }
216 226
217 Iterable mappedBy(f(E element)) => new MappedIterable<E, dynamic>(this, f); 227 Iterable mappedBy(f(E element)) {
228 return new MappedIterable<E, dynamic>(this, f);
229 }
218 230
219 reduce(initialValue, combine(previousValue, E element)) { 231 reduce(initialValue, combine(previousValue, E element)) {
220 return Collections.reduce(this, initialValue, combine); 232 return Collections.reduce(this, initialValue, combine);
221 } 233 }
222 234
223 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); 235 Iterable<E> where(bool f(E element)) {
236 return new WhereIterable<E>(this, f);
237 }
224 238
225 bool every(bool f(E element)) { 239 bool every(bool f(E element)) {
226 return Collections.every(this, f); 240 return Collections.every(this, f);
227 } 241 }
228 242
229 bool any(bool f(E element)) { 243 bool any(bool f(E element)) {
230 return Collections.any(this, f); 244 return Collections.any(this, f);
231 } 245 }
232 246
233 bool get isEmpty { 247 bool get isEmpty {
(...skipping 11 matching lines...) Expand all
245 259
246 int indexOf(E element, [int start = 0]) { 260 int indexOf(E element, [int start = 0]) {
247 return Arrays.indexOf(this, element, start, this.length); 261 return Arrays.indexOf(this, element, start, this.length);
248 } 262 }
249 263
250 int lastIndexOf(E element, [int start = null]) { 264 int lastIndexOf(E element, [int start = null]) {
251 if (start == null) start = length - 1; 265 if (start == null) start = length - 1;
252 return Arrays.lastIndexOf(this, element, start); 266 return Arrays.lastIndexOf(this, element, start);
253 } 267 }
254 268
255 Iterator<E> get iterator => new _FixedSizeArrayIterator<E>(this); 269 Iterator<E> get iterator {
270 return new _FixedSizeArrayIterator<E>(this);
271 }
256 272
257 void add(E element) { 273 void add(E element) {
258 throw new UnsupportedError( 274 throw new UnsupportedError(
259 "Cannot add to an immutable array"); 275 "Cannot add to an immutable array");
260 } 276 }
261 277
262 void addLast(E element) { 278 void addLast(E element) {
263 add(element); 279 add(element);
264 } 280 }
265 281
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 if (nextPosition < _length) { 334 if (nextPosition < _length) {
319 _current = _array[nextPosition]; 335 _current = _array[nextPosition];
320 _position = nextPosition; 336 _position = nextPosition;
321 return true; 337 return true;
322 } 338 }
323 _position = _length; 339 _position = _length;
324 _current = null; 340 _current = null;
325 return false; 341 return false;
326 } 342 }
327 343
328 E get current => _current; 344 E get current {
345 return _current;
346 }
329 } 347 }
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/byte_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698