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

Side by Side Diff: sdk/lib/internal/iterable.dart

Issue 656773002: Add concurrent modification check to ListMixin/IterableMixin.reduce. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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._internal; 5 part of dart._internal;
6 6
7 /** 7 /**
8 * Marker interface for [Iterable] subclasses that have an efficient 8 * Marker interface for [Iterable] subclasses that have an efficient
9 * [length] implementation. 9 * [length] implementation.
10 */ 10 */
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 168 }
169 return buffer.toString(); 169 return buffer.toString();
170 } 170 }
171 } 171 }
172 172
173 Iterable<E> where(bool test(E element)) => super.where(test); 173 Iterable<E> where(bool test(E element)) => super.where(test);
174 174
175 Iterable map(f(E element)) => new MappedListIterable(this, f); 175 Iterable map(f(E element)) => new MappedListIterable(this, f);
176 176
177 E reduce(E combine(var value, E element)) { 177 E reduce(E combine(var value, E element)) {
178 int length = this.length;
178 if (length == 0) throw IterableElementError.noElement(); 179 if (length == 0) throw IterableElementError.noElement();
179 E value = elementAt(0); 180 E value = elementAt(0);
180 for (int i = 1; i < length; i++) { 181 for (int i = 1; i < length; i++) {
181 value = combine(value, elementAt(i)); 182 value = combine(value, elementAt(i));
183 if (length != this.length) {
184 throw new ConcurrentModificationError(this);
185 }
186
182 } 187 }
183 return value; 188 return value;
184 } 189 }
185 190
186 fold(var initialValue, combine(var previousValue, E element)) { 191 fold(var initialValue, combine(var previousValue, E element)) {
187 var value = initialValue; 192 var value = initialValue;
188 int length = this.length; 193 int length = this.length;
189 for (int i = 0; i < length; i++) { 194 for (int i = 0; i < length; i++) {
190 value = combine(value, elementAt(i)); 195 value = combine(value, elementAt(i));
191 if (length != this.length) { 196 if (length != this.length) {
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 * Creates errors throw by [Iterable] when the element count is wrong. 1170 * Creates errors throw by [Iterable] when the element count is wrong.
1166 */ 1171 */
1167 abstract class IterableElementError { 1172 abstract class IterableElementError {
1168 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */ 1173 /** Error thrown thrown by, e.g., [Iterable.first] when there is no result. */
1169 static StateError noElement() => new StateError("No element"); 1174 static StateError noElement() => new StateError("No element");
1170 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */ 1175 /** Error thrown by, e.g., [Iterable.single] if there are too many results. */
1171 static StateError tooMany() => new StateError("Too many elements"); 1176 static StateError tooMany() => new StateError("Too many elements");
1172 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */ 1177 /** Error thrown by, e.g., [List.setRange] if there are too few elements. */
1173 static StateError tooFew() => new StateError("Too few elements"); 1178 static StateError tooFew() => new StateError("Too few elements");
1174 } 1179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698