[vm/corelib] Shrink code size of inlined _GrowableList.add
Previously, _GrowableList.add used 2 calls to grow the list which
results in extra code generated for each inlined List.add call.
This change replaces
_grow(_nextCapacity(len));
with
_growToNextCapacity();
which reduces code size.
Flutter gallery in release mode
instructions size -0.32% (arm), -0.1% (arm64)
total snapshot size -0.19% (arm) -0.06% (arm64)
Change-Id: I8422757d147ecec5bdec60910c65c558c39fde1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175006
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
diff --git a/sdk/lib/_internal/vm/lib/growable_array.dart b/sdk/lib/_internal/vm/lib/growable_array.dart
index 537fb34..865b874 100644
--- a/sdk/lib/_internal/vm/lib/growable_array.dart
+++ b/sdk/lib/_internal/vm/lib/growable_array.dart
@@ -261,7 +261,7 @@
void add(T value) {
var len = length;
if (len == _capacity) {
- _grow(_nextCapacity(len));
+ _growToNextCapacity();
}
_setLength(len + 1);
this[len] = value;
@@ -310,7 +310,7 @@
if (this.length != newLen) throw new ConcurrentModificationError(this);
len = newLen;
}
- _grow(_nextCapacity(_capacity));
+ _growToNextCapacity();
} while (true);
}
@@ -370,6 +370,14 @@
_setData(newData);
}
+ // This method is marked as never-inline to conserve code size.
+ // It is called in rare cases, but used in the add() which is
+ // used very often and always inlined.
+ @pragma("vm:never-inline")
+ void _growToNextCapacity() {
+ _grow(_nextCapacity(_capacity));
+ }
+
void _shrink(int new_capacity, int new_length) {
var newData = _allocateData(new_capacity);
// This is a work-around for dartbug.com/30090. See the comment in _grow.