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

Unified Diff: runtime/lib/array_patch.dart

Issue 1999793002: Make Iterable.toList more efficient if the length is known. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Avoid iterator for empty list Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/typed_data.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/array_patch.dart
diff --git a/runtime/lib/array_patch.dart b/runtime/lib/array_patch.dart
index c0ddfeec1c35bdde3963c3b31b4d8107b0650c84..94f29f195fc3404ab3a461577fd72bd8a3ee030e 100644
--- a/runtime/lib/array_patch.dart
+++ b/runtime/lib/array_patch.dart
@@ -36,8 +36,10 @@ patch class List<E> {
if (elements is EfficientLength) {
int length = elements.length;
var list = growable ? new _GrowableList<E>(length) : new _List<E>(length);
- int i = 0;
- for (var element in elements) { list[i++] = element; }
+ if (length > 0) { // Avoid creating iterator unless necessary.
+ int i = 0;
+ for (var element in elements) { list[i++] = element; }
+ }
return list;
}
List<E> list = new _GrowableList<E>(0);
@@ -47,7 +49,7 @@ patch class List<E> {
if (growable) return list;
if (list.length == 0) {
// Avoid getting an immutable list from makeListFixedLength.
- return new List<E>(0);
+ return new _List<E>(0);
}
return makeListFixedLength(list);
}
« no previous file with comments | « no previous file | runtime/lib/typed_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698