| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class _GrowableList<T> implements List<T> { | 5 class _GrowableList<T> implements List<T> { |
| 6 static final int _classId = ClassID.getID(new _GrowableList(0)); | |
| 7 | 6 |
| 8 void insert(int index, T element) { | 7 void insert(int index, T element) { |
| 9 if (index < 0 || index > length) { | 8 if ((index < 0) || (index > length)) { |
| 10 throw new RangeError.range(index, 0, length); | 9 throw new RangeError.range(index, 0, length); |
| 11 } | 10 } |
| 12 if (index == this.length) { | 11 if (index == this.length) { |
| 13 add(element); | 12 add(element); |
| 14 return; | 13 return; |
| 15 } | 14 } |
| 16 int oldLength = this.length; | 15 int oldLength = this.length; |
| 17 // We are modifying the length just below the is-check. Without the check | 16 // We are modifying the length just below the is-check. Without the check |
| 18 // Array.copy could throw an exception, leaving the list in a bad state | 17 // Array.copy could throw an exception, leaving the list in a bad state |
| 19 // (with a length that has been increased, but without a new element). | 18 // (with a length that has been increased, but without a new element). |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 Lists.indicesCheck(this, start, end); | 102 Lists.indicesCheck(this, start, end); |
| 104 if (end == null) end = this.length; | 103 if (end == null) end = this.length; |
| 105 int length = end - start; | 104 int length = end - start; |
| 106 if (start == end) return <T>[]; | 105 if (start == end) return <T>[]; |
| 107 List list = new _GrowableList<T>.withCapacity(length); | 106 List list = new _GrowableList<T>.withCapacity(length); |
| 108 list.length = length; | 107 list.length = length; |
| 109 Lists.copy(this, start, list, 0, length); | 108 Lists.copy(this, start, list, 0, length); |
| 110 return list; | 109 return list; |
| 111 } | 110 } |
| 112 | 111 |
| 113 static final int _kDefaultCapacity = 2; | 112 static const int _kDefaultCapacity = 2; |
| 114 | 113 |
| 115 factory _GrowableList(int length) { | 114 factory _GrowableList(int length) { |
| 116 var data = new _List((length == 0) ? _kDefaultCapacity : length); | 115 var data = new _List((length == 0) ? _kDefaultCapacity : length); |
| 117 var result = new _GrowableList<T>.withData(data); | 116 var result = new _GrowableList<T>.withData(data); |
| 118 if (length > 0) { | 117 if (length > 0) { |
| 119 result._setLength(length); | 118 result._setLength(length); |
| 120 } | 119 } |
| 121 return result; | 120 return result; |
| 122 } | 121 } |
| 123 | 122 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 } | 339 } |
| 341 | 340 |
| 342 Set<T> toSet() { | 341 Set<T> toSet() { |
| 343 return new Set<T>.from(this); | 342 return new Set<T>.from(this); |
| 344 } | 343 } |
| 345 | 344 |
| 346 Map<int, T> asMap() { | 345 Map<int, T> asMap() { |
| 347 return IterableMixinWorkaround.asMapList(this); | 346 return IterableMixinWorkaround.asMapList(this); |
| 348 } | 347 } |
| 349 } | 348 } |
| OLD | NEW |