Chromium Code Reviews| Index: sdk/lib/collection/list.dart |
| diff --git a/sdk/lib/collection/list.dart b/sdk/lib/collection/list.dart |
| index d4dac6a4e9ccb9b436ff68cf1237de009b59c6ac..850aa890f5271a51d602c1b111eaf153224e665b 100644 |
| --- a/sdk/lib/collection/list.dart |
| +++ b/sdk/lib/collection/list.dart |
| @@ -80,12 +80,8 @@ abstract class ListMixin<E> implements List<E> { |
| } |
| bool contains(Object element) { |
| - int length = this.length; |
| - for (int i = 0; i < length; i++) { |
| + for (int i = 0; i < this.length; i++) { |
| if (this[i] == element) return true; |
|
Lasse Reichstein Nielsen
2014/02/03 13:27:44
If the '==' operator on the elements modify the li
vicb
2014/02/03 13:38:30
I haven't thought about operator overloading here.
Lasse Reichstein Nielsen
2014/02/04 12:32:00
Pretty unusual, hopefully.
While we could probabl
vicb
2014/02/04 13:00:31
Crashing because of the check or because of any ot
|
| - if (length != this.length) { |
| - throw new ConcurrentModificationError(this); |
| - } |
| } |
| return false; |
| } |
| @@ -160,32 +156,14 @@ abstract class ListMixin<E> implements List<E> { |
| } |
| String join([String separator = ""]) { |
| - int length = this.length; |
| - if (!separator.isEmpty) { |
| - if (length == 0) return ""; |
| - String first = "${this[0]}"; |
| - if (length != this.length) { |
| - throw new ConcurrentModificationError(this); |
| - } |
| - StringBuffer buffer = new StringBuffer(first); |
| - for (int i = 1; i < length; i++) { |
| - buffer.write(separator); |
| - buffer.write(this[i]); |
| - if (length != this.length) { |
| - throw new ConcurrentModificationError(this); |
| - } |
| - } |
| - return buffer.toString(); |
| + if (this.length == 0) return ""; |
| + StringBuffer buffer = new StringBuffer(); |
| + if (separator.isEmpty) { |
| + buffer.writeAll(this); |
| } else { |
| - StringBuffer buffer = new StringBuffer(); |
| - for (int i = 0; i < length; i++) { |
| - buffer.write(this[i]); |
| - if (length != this.length) { |
| - throw new ConcurrentModificationError(this); |
| - } |
| - } |
| - return buffer.toString(); |
| + buffer.writeAll(this, separator); |
| } |
| + return buffer.toString(); |
|
Lasse Reichstein Nielsen
2014/02/03 13:27:44
This change looks ok, if performance is as good (o
vicb
2014/02/03 13:38:30
I haven't seen much of a change in perf - it shoul
Lasse Reichstein Nielsen
2014/02/04 12:32:00
I see marginally slower (very, very marginally), p
|
| } |
| Iterable<E> where(bool test(E element)) => new WhereIterable<E>(this, test); |