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 part of dart.collection; | 5 part of dart.collection; |
6 | 6 |
7 /** | 7 /** |
8 * This class provides default implementations for Iterables (including Lists). | 8 * This class provides default implementations for Iterables (including Lists). |
9 * | 9 * |
10 * Once Dart receives Mixins it will be replaced with mixin classes. | 10 * Once Dart receives Mixins it will be replaced with mixin classes. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 for (int i = 0; i < length; i++) { | 124 for (int i = 0; i < length; i++) { |
125 var element = list[i]; | 125 var element = list[i]; |
126 if (!test(element)) { | 126 if (!test(element)) { |
127 retained.add(element); | 127 retained.add(element); |
128 } | 128 } |
129 if (length != list.length) { | 129 if (length != list.length) { |
130 throw new ConcurrentModificationError(list); | 130 throw new ConcurrentModificationError(list); |
131 } | 131 } |
132 } | 132 } |
133 if (retained.length == length) return; | 133 if (retained.length == length) return; |
| 134 list.length = retained.length; |
134 for (int i = 0; i < retained.length; i++) { | 135 for (int i = 0; i < retained.length; i++) { |
135 list[i] = retained[i]; | 136 list[i] = retained[i]; |
136 } | 137 } |
137 list.length = retained.length; | |
138 } | 138 } |
139 | 139 |
140 /** | 140 /** |
141 * Simple implemenation for [Collection.retainMatching]. | 141 * Simple implemenation for [Collection.retainMatching]. |
142 * | 142 * |
143 * This implementation assumes that [Collecton.removeAll] on [collection] is | 143 * This implementation assumes that [Collecton.removeAll] on [collection] is |
144 * efficient. | 144 * efficient. |
145 */ | 145 */ |
146 static void retainMatching(Collection collection, bool test(var element)) { | 146 static void retainMatching(Collection collection, bool test(var element)) { |
147 List elementsToRemove = []; | 147 List elementsToRemove = []; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 * The source of the elements may be a [List] or any [Iterable] with | 368 * The source of the elements may be a [List] or any [Iterable] with |
369 * efficient [Iterable.length] and [Iterable.elementAt]. | 369 * efficient [Iterable.length] and [Iterable.elementAt]. |
370 */ | 370 */ |
371 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { | 371 class UnmodifiableListView<E> extends UnmodifiableListBase<E> { |
372 Iterable<E> _source; | 372 Iterable<E> _source; |
373 /** Create an unmodifiable list backed by [source]. */ | 373 /** Create an unmodifiable list backed by [source]. */ |
374 UnmodifiableListView(Iterable<E> source) : _source = source; | 374 UnmodifiableListView(Iterable<E> source) : _source = source; |
375 int get length => _source.length; | 375 int get length => _source.length; |
376 E operator[](int index) => _source.elementAt(index); | 376 E operator[](int index) => _source.elementAt(index); |
377 } | 377 } |
OLD | NEW |