Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1682)

Unified Diff: runtime/lib/growable_array.dart

Issue 2240313002: - Fix for issue 27054 (leak when removing element from _GrowableList) (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/method_recognizer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | runtime/vm/method_recognizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698