Index: runtime/lib/growable_array.dart |
=================================================================== |
--- runtime/lib/growable_array.dart (revision 1805) |
+++ runtime/lib/growable_array.dart (working copy) |
@@ -47,7 +47,7 @@ |
if (start < 0 || start > this.length) { |
throw new IndexOutOfRangeException(start); |
} |
- if (this.length + length >= backingArray.length) { |
+ if (this.length + length > backingArray.length) { |
grow(backingArray.length + length); |
} |
Arrays.copy(backingArray, |
@@ -72,8 +72,10 @@ |
return list; |
} |
- // The length of this growable array. It is always less than the |
- // length of the backing array. |
+ // The length of this growable array. It is always less than or equal to the |
+ // length of the backing array, which itself is always greater than 0, so that |
+ // grow() does not have to check for a zero length backing array before |
+ // doubling its size. |
int _length; |
GrowableObjectArray() |
@@ -87,14 +89,6 @@ |
backingArray = new ObjectArray<T>(capacity); |
} |
- GrowableObjectArray._usingArray(List<T> array) { |
- backingArray = array; |
- _length = array.length; |
- if (_length == 0) { |
- grow(4); |
- } |
- } |
- |
factory GrowableObjectArray<T>.from(Collection<T> other) { |
List<T> result = new GrowableObjectArray<T>(); |
result.addAll(other); |
@@ -106,7 +100,7 @@ |
} |
void set length(int new_length) { |
- if (new_length >= backingArray.length) { |
+ if (new_length > backingArray.length) { |
grow(new_length); |
} else { |
for (int i = new_length; i < _length; i++) { |