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

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

Issue 11956039: Revert "Create IterableMixinWorkaround and move most of the Collections methods there." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « runtime/lib/byte_array.dart ('k') | samples/swarm/DataSource.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 class _GrowableObjectArray<T> implements List<T> { 5 class _GrowableObjectArray<T> implements List<T> {
6 factory _GrowableObjectArray._uninstantiable() { 6 factory _GrowableObjectArray._uninstantiable() {
7 throw new UnsupportedError( 7 throw new UnsupportedError(
8 "GrowableObjectArray can only be allocated by the VM"); 8 "GrowableObjectArray can only be allocated by the VM");
9 } 9 }
10 10
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (length > 0) return this[length - 1]; 156 if (length > 0) return this[length - 1];
157 throw new StateError("No elements"); 157 throw new StateError("No elements");
158 } 158 }
159 159
160 T get single { 160 T get single {
161 if (length == 1) return this[0]; 161 if (length == 1) return this[0];
162 if (length == 0) throw new StateError("No elements"); 162 if (length == 0) throw new StateError("No elements");
163 throw new StateError("More than one element"); 163 throw new StateError("More than one element");
164 } 164 }
165 165
166 T min([int compare(T a, T b)]) => IterableMixinWorkaround.min(this, compare); 166 T min([int compare(T a, T b)]) => Collections.min(this, compare);
167 167
168 T max([int compare(T a, T b)]) => IterableMixinWorkaround.max(this, compare); 168 T max([int compare(T a, T b)]) => Collections.max(this, compare);
169 169
170 int indexOf(T element, [int start = 0]) { 170 int indexOf(T element, [int start = 0]) {
171 return Arrays.indexOf(this, element, start, length); 171 return Arrays.indexOf(this, element, start, length);
172 } 172 }
173 173
174 int lastIndexOf(T element, [int start = null]) { 174 int lastIndexOf(T element, [int start = null]) {
175 if (start == null) start = length - 1; 175 if (start == null) start = length - 1;
176 return Arrays.lastIndexOf(this, element, start); 176 return Arrays.lastIndexOf(this, element, start);
177 } 177 }
178 178
179 void _grow(int new_length) { 179 void _grow(int new_length) {
180 var new_data = new _ObjectArray<T>(new_length); 180 var new_data = new _ObjectArray<T>(new_length);
181 for (int i = 0; i < length; i++) { 181 for (int i = 0; i < length; i++) {
182 new_data[i] = this[i]; 182 new_data[i] = this[i];
183 } 183 }
184 _setData(new_data); 184 _setData(new_data);
185 } 185 }
186 186
187 // Collection interface. 187 // Collection interface.
188 188
189 bool contains(T element) { 189 bool contains(T element) {
190 return IterableMixinWorkaround.contains(this, element); 190 return Collections.contains(this, element);
191 } 191 }
192 192
193 void forEach(f(T element)) { 193 void forEach(f(T element)) {
194 // TODO(srdjan): Use IterableMixinWorkaround.forEach(this, f); 194 // TODO(srdjan): Use Collections.forEach(this, f);
195 // Accessing the list directly improves DeltaBlue performance by 25%. 195 // Accessing the list directly improves DeltaBlue performance by 25%.
196 for (int i = 0; i < length; i++) { 196 for (int i = 0; i < length; i++) {
197 f(this[i]); 197 f(this[i]);
198 } 198 }
199 } 199 }
200 200
201 String join([String separator]) { 201 String join([String separator]) {
202 if (isEmpty) return ""; 202 if (isEmpty) return "";
203 if (this.length == 1) return "${this[0]}"; 203 if (this.length == 1) return "${this[0]}";
204 StringBuffer buffer = new StringBuffer(); 204 StringBuffer buffer = new StringBuffer();
205 if (separator == null || separator == "") { 205 if (separator == null || separator == "") {
206 for (int i = 0; i < this.length; i++) { 206 for (int i = 0; i < this.length; i++) {
207 buffer.add("${this[i]}"); 207 buffer.add("${this[i]}");
208 } 208 }
209 } else { 209 } else {
210 buffer.add("${this[0]}"); 210 buffer.add("${this[0]}");
211 for (int i = 1; i < this.length; i++) { 211 for (int i = 1; i < this.length; i++) {
212 buffer.add(separator); 212 buffer.add(separator);
213 buffer.add("${this[i]}"); 213 buffer.add("${this[i]}");
214 } 214 }
215 } 215 }
216 return buffer.toString(); 216 return buffer.toString();
217 } 217 }
218 218
219 List mappedBy(f(T element)) { 219 List mappedBy(f(T element)) {
220 return IterableMixinWorkaround.mappedByList(this, f); 220 return new MappedList<T, dynamic>(this, f);
221 } 221 }
222 222
223 reduce(initialValue, combine(previousValue, T element)) { 223 reduce(initialValue, combine(previousValue, T element)) {
224 return IterableMixinWorkaround.reduce(this, initialValue, combine); 224 return Collections.reduce(this, initialValue, combine);
225 } 225 }
226 226
227 Iterable<T> where(bool f(T element)) { 227 Iterable<T> where(bool f(T element)) {
228 return IterableMixinWorkaround.where(this, f); 228 return new WhereIterable<T>(this, f);
229 } 229 }
230 230
231 List<T> take(int n) { 231 List<T> take(int n) {
232 return IterableMixinWorkaround.takeList(this, n); 232 return new ListView<T>(this, 0, n);
233 } 233 }
234 234
235 Iterable<T> takeWhile(bool test(T value)) { 235 Iterable<T> takeWhile(bool test(T value)) {
236 return IterableMixinWorkaround.takeWhile(this, test); 236 return new TakeWhileIterable<T>(this, test);
237 } 237 }
238 238
239 List<T> skip(int n) { 239 List<T> skip(int n) {
240 return IterableMixinWorkaround.skipList(this, n); 240 return new ListView<T>(this, n, null);
241 } 241 }
242 242
243 Iterable<T> skipWhile(bool test(T value)) { 243 Iterable<T> skipWhile(bool test(T value)) {
244 return IterableMixinWorkaround.skipWhile(this, test); 244 return new SkipWhileIterable<T>(this, test);
245 } 245 }
246 246
247 bool every(bool f(T element)) { 247 bool every(bool f(T element)) {
248 return IterableMixinWorkaround.every(this, f); 248 return Collections.every(this, f);
249 } 249 }
250 250
251 bool any(bool f(T element)) { 251 bool any(bool f(T element)) {
252 return IterableMixinWorkaround.any(this, f); 252 return Collections.any(this, f);
253 } 253 }
254 254
255 T firstMatching(bool test(T value), {T orElse()}) { 255 T firstMatching(bool test(T value), {T orElse()}) {
256 return IterableMixinWorkaround.firstMatching(this, test, orElse); 256 return Collections.firstMatching(this, test, orElse);
257 } 257 }
258 258
259 T lastMatching(bool test(T value), {T orElse()}) { 259 T lastMatching(bool test(T value), {T orElse()}) {
260 return IterableMixinWorkaround.lastMatchingInList(this, test, orElse); 260 return Collections.lastMatchingInList(this, test, orElse);
261 } 261 }
262 262
263 T singleMatching(bool test(T value)) { 263 T singleMatching(bool test(T value)) {
264 return IterableMixinWorkaround.singleMatching(this, test); 264 return Collections.singleMatching(this, test);
265 } 265 }
266 266
267 T elementAt(int index) { 267 T elementAt(int index) {
268 return this[index]; 268 return this[index];
269 } 269 }
270 270
271 bool get isEmpty { 271 bool get isEmpty {
272 return this.length == 0; 272 return this.length == 0;
273 } 273 }
274 274
(...skipping 15 matching lines...) Expand all
290 } 290 }
291 291
292 List<T> toList() { 292 List<T> toList() {
293 return new List<T>.from(this); 293 return new List<T>.from(this);
294 } 294 }
295 295
296 Set<T> toSet() { 296 Set<T> toSet() {
297 return new Set<T>.from(this); 297 return new Set<T>.from(this);
298 } 298 }
299 } 299 }
OLDNEW
« no previous file with comments | « runtime/lib/byte_array.dart ('k') | samples/swarm/DataSource.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698