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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/core_patch.dart

Issue 11312122: Change List constructors. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload. Adapt code for List.fixedLength. Created 8 years 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
Index: sdk/lib/_internal/compiler/implementation/lib/core_patch.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/core_patch.dart b/sdk/lib/_internal/compiler/implementation/lib/core_patch.dart
index 5df7994bb5e6f62199bdd7bc379146c5a56856cd..92067ecb6de7022e9934014807b0d0ed03284162 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/core_patch.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/core_patch.dart
@@ -159,7 +159,44 @@ patch class _StopwatchImpl {
// Patch for List implementation.
patch class _ListImpl<E> {
- patch factory List([int length]) => Primitives.newList(length);
+ patch factory List([int length = 0]) {
+ if ((length is !int) || (length < 0)) {
+ String lengthString = Error.safeToString(length);
+ throw new ArgumentError(
+ "Length must be a positive integer: $lengthString.");
+ }
+ return Primitives.newGrowableList(length);
+ }
+
+ patch factory List.fixedLength(int length, {E fill: null}) {
+ if ((length is !int) || (length < 0)) {
+ throw new ArgumentError("Length must be a positive integer: $length.");
+ }
+ List result = Primitives.newFixedList(length);
+ if (length != 0 && fill != null) {
+ for (int i = 0; i < result.length; i++) {
+ result[i] = fill;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Creates an extendable list of the given [length] where each entry is
+ * filled with [fill].
+ */
+ patch factory List.filled(int length, E fill) {
+ if ((length is !int) || (length < 0)) {
+ throw new ArgumentError("Length must be a positive integer: $length.");
+ }
+ List result = Primitives.newGrowableList(length);
+ if (length != 0 && fill != null) {
+ for (int i = 0; i < result.length; i++) {
+ result[i] = fill;
+ }
+ }
+ return result;
+ }
patch factory List.from(Iterable<E> other) {
var result = new List();

Powered by Google App Engine
This is Rietveld 408576698