Chromium Code Reviews| Index: pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart |
| diff --git a/pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart b/pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart |
| index 4a4c082101754059cc1b81a6d0be7acfcb5f6b36..d03ee92d03dad3b643d42b8da7b6a72a59211d20 100644 |
| --- a/pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart |
| +++ b/pkg/dev_compiler/tool/input_sdk/patch/core_patch.dart |
| @@ -15,6 +15,8 @@ import 'dart:_js_helper' |
| JsLinkedHashMap, |
| JSSyntaxRegExp, |
| NoInline, |
| + notNull, |
| + nullCheck, |
| objectHashCode, |
| Primitives, |
| stringJoinUnchecked; |
| @@ -319,14 +321,14 @@ class Stopwatch { |
| @patch |
| class List<E> { |
| @patch |
| - factory List([int length]) { |
| + factory List([int _length]) { |
| dynamic list; |
| - if (length == null) { |
| + if (_length == null) { |
| list = JS('', '[]'); |
| } else { |
| - // Explicit type test is necessary to guard against JavaScript conversions |
| - // in unchecked mode. |
| - if ((length is! int) || (length < 0)) { |
| + @notNull |
| + var length = _length; |
| + if (length < 0) { |
| throw new ArgumentError( |
| "Length must be a non-negative integer: $length"); |
| } |
| @@ -339,19 +341,29 @@ class List<E> { |
| factory List.filled(int length, E fill, {bool growable: true}) { |
| List<E> result = new List<E>(length); |
| if (length != 0 && fill != null) { |
| - for (int i = 0; i < result.length; i++) { |
| + @notNull |
| + var length = result.length; |
| + for (int i = 0; i < length; i++) { |
| result[i] = fill; |
| } |
| } |
| if (growable) return result; |
| - return makeListFixedLength/*<E>*/(result); |
| + return makeListFixedLength<E>(result); |
| } |
| @patch |
| factory List.from(Iterable elements, {bool growable: true}) { |
| List<E> list = new List<E>(); |
| - for (var e in elements) { |
| - list.add(e); |
| + // Specialize the copy loop for the case that doesn't need a |
| + // runtime check. |
| + if (elements is Iterable<E>) { |
| + for (var e in elements) { |
| + list.add(e); |
| + } |
| + } else { |
| + for (var e in elements) { |
| + list.add(e); |
|
Jennifer Messerly
2017/08/22 21:54:40
make `as E` explicit?
I'm thinking of disabling i
Leaf
2017/08/23 17:26:13
Done.
|
| + } |
| } |
| if (growable) return list; |
| return makeListFixedLength/*<E>*/(list); |