Files
sdk/runtime/lib/array_patch.dart
T
regis@google.com 02a8df0c83 Remove private class helping the parser to construct literal lists and maps.
Patch List and Map (implementation) classes with literal factories.
Review URL: https://codereview.chromium.org//11369234

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14873 260f80e4-7a28-3924-810f-c04153c831b5
2012-11-14 04:28:02 +00:00

36 lines
1.1 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Note that the optimizing compiler depends on the algorithm which
// 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.from(Iterable<E> other) {
_GrowableObjectArray<E> list = new _GrowableObjectArray<E>();
for (final e in other) {
list.add(e);
}
return list;
}
// Factory constructing a mutable List from a parser generated List literal.
// [elements] contains elements that are already type checked.
factory List._fromLiteral(List elements) {
var list = new List<E>();
if (elements.length > 0) {
list._setData(elements);
list.length = elements.length;
}
return list;
}
}