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

Unified Diff: runtime/lib/array_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
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | runtime/lib/math_patch.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 5bb7ec2c2ad176f5c4977b21ea7ea057bb63e02d..7000164774e1c12c8064b8d4de3b8366640d90b6 100644
--- a/runtime/lib/array_patch.dart
+++ b/runtime/lib/array_patch.dart
@@ -6,12 +6,43 @@
// returns a _GrowableObjectArray if length is null, otherwise returns
// fixed size array.
patch class _ListImpl<E> {
- /* patch */ factory List([int length = null]) {
- if (length == null) {
- return new _GrowableObjectArray<E>();
- } else {
- return new _ObjectArray<E>(length);
+ /* patch */ factory List([int length = 0]) {
+ if (length is! int || length < 0) {
+ throw new ArgumentError("Length must be a positive integer: $length.");
}
+ _GrowableObjectArray<E> result = new _GrowableObjectArray<E>();
+ result.length = length;
+ return result;
+ }
+
+ /* 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.");
+ }
+ _ObjectArray<E> result = new _ObjectArray<E>(length);
+ if (fill != null) {
+ for (int i = 0; i < length; i++) {
+ result[i] = fill;
+ }
+ }
+ return result;
+ }
+
+ /* patch */ factory List.filled(int length, E fill) {
+ if (length is! int || length < 0) {
+ throw new ArgumentError("Length must be a positive integer: $length.");
+ }
+ _GrowableObjectArray<E> result =
+ new _GrowableObjectArray<E>.withCapacity(length < 4 ? 4 : length);
+ if (length != 0) {
+ result.length = length;
+ if (fill != null) {
+ for (int i = 0; i < length; i++) {
+ result[i] = fill;
+ }
+ }
+ }
+ return result;
}
/* patch */ factory List.from(Iterable<E> other) {
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | runtime/lib/math_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698