Index: runtime/lib/growable_array.dart |
diff --git a/runtime/lib/growable_array.dart b/runtime/lib/growable_array.dart |
index 271c71a12264d2c0928dbe82dc9a3ef853725ec1..9e942e4c5fc112a08194f5667345a3faf1456fd6 100644 |
--- a/runtime/lib/growable_array.dart |
+++ b/runtime/lib/growable_array.dart |
@@ -112,8 +112,19 @@ class _GrowableList<T> extends ListBase<T> { |
int get length native "GrowableList_getLength"; |
void set length(int new_length) { |
- int new_capacity = (new_length == 0) ? _kDefaultCapacity : new_length; |
- if (new_capacity > _capacity) { |
+ int old_capacity = _capacity; |
+ int new_capacity = new_length; |
+ if (new_length == 0) { |
+ // Ensure that we use _kDefaultCapacity only when the old_capacity |
+ // is greater than _kDefaultCapacity otherwise we end up growing the |
+ // the array. |
+ if (old_capacity < _kDefaultCapacity) { |
+ new_capacity = old_capacity; |
+ } else { |
+ new_capacity = _kDefaultCapacity; |
+ } |
+ } |
+ if (new_capacity > old_capacity) { |
_grow(new_capacity); |
_setLength(new_length); |
return; |
@@ -203,8 +214,7 @@ class _GrowableList<T> extends ListBase<T> { |
T removeLast() { |
var len = length - 1; |
var elem = this[len]; |
- this[len] = null; |
- _setLength(len); |
+ this.length = len; |
return elem; |
} |