| OLD | NEW |
| 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 _GrowableList<T> implements List<T> { | 5 class _GrowableList<T> implements List<T> { |
| 6 | 6 |
| 7 void insert(int index, T element) { | 7 void insert(int index, T element) { |
| 8 if ((index < 0) || (index > length)) { | 8 if ((index < 0) || (index > length)) { |
| 9 throw new RangeError.range(index, 0, length); | 9 throw new RangeError.range(index, 0, length); |
| 10 } | 10 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 250 |
| 251 void forEach(f(T element)) { | 251 void forEach(f(T element)) { |
| 252 int initialLength = length; | 252 int initialLength = length; |
| 253 for (int i = 0; i < length; i++) { | 253 for (int i = 0; i < length; i++) { |
| 254 f(this[i]); | 254 f(this[i]); |
| 255 if (length != initialLength) throw new ConcurrentModificationError(this); | 255 if (length != initialLength) throw new ConcurrentModificationError(this); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 String join([String separator = ""]) { | 259 String join([String separator = ""]) { |
| 260 if (isEmpty) return ""; | 260 final int length = this.length; |
| 261 if (this.length == 1) return "${this[0]}"; | 261 if (length == 0) return ""; |
| 262 if (length == 1) return "${this[0]}"; |
| 263 if (separator.isNotEmpty) return _joinWithSeparator(separator); |
| 264 var i = 0; |
| 265 var codeUnitCount = 0; |
| 266 while (i < length) { |
| 267 final element = this[i]; |
| 268 final int cid = ClassID.getID(element); |
| 269 if (ClassID.cidOneByteString == cid) { |
| 270 codeUnitCount += element.length; |
| 271 i++; |
| 272 continue; |
| 273 } |
| 274 final int firstNonOneByteStringLimit = i; |
| 275 var nextElement = element; |
| 276 while (nextElement is String) { |
| 277 i++; |
| 278 if (i == length) { |
| 279 return _StringBase._concatRangeNative(this, 0, length); |
| 280 } |
| 281 nextElement = this[i]; |
| 282 } |
| 283 // return _StringBase._interpolate(this); |
| 284 final list = new _List(length); |
| 285 for (int copyIndex = 0; copyIndex < i; copyIndex++) { |
| 286 list[copyIndex] = this[copyIndex]; |
| 287 } |
| 288 // Is non-zero if list contains a non-onebyte string |
| 289 var onebyteCanary = i - firstNonOneByteStringLimit; |
| 290 while (true) { |
| 291 final element = |
| 292 (nextElement is String) ? nextElement |
| 293 :_forceToString(nextElement); |
| 294 onebyteCanary |= (ClassID.getID(element) ^ ClassID.cidOneByteString); |
| 295 list[i] = element; |
| 296 codeUnitCount += element.length; |
| 297 i++; |
| 298 if (i == length) break; |
| 299 nextElement = this[i]; |
| 300 } |
| 301 if (onebyteCanary == 0) { |
| 302 return _OneByteString._concatAll(list, codeUnitCount); |
| 303 } |
| 304 return _StringBase._concatRangeNative(list, 0, length); |
| 305 } |
| 306 return _OneByteString._concatAll(this, codeUnitCount); |
| 307 } |
| 308 |
| 309 static String _forceToString(Object object) { |
| 310 assert(object is! String); |
| 311 final result = object.toString(); |
| 312 if (result is String) return result; |
| 313 throw new ArgumentError(object); |
| 314 } |
| 315 |
| 316 String _joinWithSeparator(String separator) { |
| 262 StringBuffer buffer = new StringBuffer(); | 317 StringBuffer buffer = new StringBuffer(); |
| 263 if (separator.isEmpty) { | 318 buffer.write(this[0]); |
| 264 for (int i = 0; i < this.length; i++) { | 319 for (int i = 1; i < this.length; i++) { |
| 265 buffer.write(this[i]); | 320 buffer.write(separator); |
| 266 } | 321 buffer.write(this[i]); |
| 267 } else { | |
| 268 buffer.write(this[0]); | |
| 269 for (int i = 1; i < this.length; i++) { | |
| 270 buffer.write(separator); | |
| 271 buffer.write(this[i]); | |
| 272 } | |
| 273 } | 322 } |
| 274 return buffer.toString(); | 323 return buffer.toString(); |
| 275 } | 324 } |
| 276 | 325 |
| 277 Iterable map(f(T element)) { | 326 Iterable map(f(T element)) { |
| 278 return IterableMixinWorkaround.mapList(this, f); | 327 return IterableMixinWorkaround.mapList(this, f); |
| 279 } | 328 } |
| 280 | 329 |
| 281 T reduce(T combine(T value, T element)) { | 330 T reduce(T combine(T value, T element)) { |
| 282 return IterableMixinWorkaround.reduce(this, combine); | 331 return IterableMixinWorkaround.reduce(this, combine); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 426 } |
| 378 | 427 |
| 379 Set<T> toSet() { | 428 Set<T> toSet() { |
| 380 return new Set<T>.from(this); | 429 return new Set<T>.from(this); |
| 381 } | 430 } |
| 382 | 431 |
| 383 Map<int, T> asMap() { | 432 Map<int, T> asMap() { |
| 384 return new IterableMixinWorkaround<T>().asMapList(this); | 433 return new IterableMixinWorkaround<T>().asMapList(this); |
| 385 } | 434 } |
| 386 } | 435 } |
| OLD | NEW |