Skip to content

Commit fdd01da

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/compiler] Streamline code generated for empty list literals
Previously, empty list literals were generated as List<E>._fromLiteral(const []) List._fromLiteral checks if the argument is an empty list and calls _GrowableList<E>(0) in such case. If List._fromLiteral is not inlined, this adds an unnecessary overhead. Now empty list literals are generated more directly as _GrowableList<E>(0) Havlak +15.58% in AOT mode with null safety. Change-Id: I6723e1e912cd0bbcbbb622f928d912c554217e5e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159201 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Vyacheslav Egorov <[email protected]> Reviewed-by: Régis Crelier <[email protected]>
1 parent a443e60 commit fdd01da

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,24 +3780,30 @@ Fragment StreamingFlowGraphBuilder::BuildListLiteral(TokenPosition* p) {
37803780

37813781
// The type argument for the factory call.
37823782
Fragment instructions = TranslateInstantiatedTypeArguments(type_arguments);
3783+
3784+
if (length == 0) {
3785+
instructions += IntConstant(0);
3786+
instructions += StaticCall(
3787+
position,
3788+
Function::ZoneHandle(Z, I->object_store()->growable_list_factory()), 2,
3789+
ICData::kStatic);
3790+
return instructions;
3791+
}
3792+
37833793
LocalVariable* type = MakeTemporary();
3794+
instructions += LoadLocal(type);
37843795

3796+
// The type arguments for CreateArray.
37853797
instructions += LoadLocal(type);
3786-
if (length == 0) {
3787-
instructions += Constant(Object::empty_array());
3788-
} else {
3789-
// The type arguments for CreateArray.
3790-
instructions += LoadLocal(type);
3791-
instructions += IntConstant(length);
3792-
instructions += CreateArray();
3798+
instructions += IntConstant(length);
3799+
instructions += CreateArray();
37933800

3794-
LocalVariable* array = MakeTemporary();
3795-
for (intptr_t i = 0; i < length; ++i) {
3796-
instructions += LoadLocal(array);
3797-
instructions += IntConstant(i);
3798-
instructions += BuildExpression(); // read ith expression.
3799-
instructions += StoreIndexed(kArrayCid);
3800-
}
3801+
LocalVariable* array = MakeTemporary();
3802+
for (intptr_t i = 0; i < length; ++i) {
3803+
instructions += LoadLocal(array);
3804+
instructions += IntConstant(i);
3805+
instructions += BuildExpression(); // read ith expression.
3806+
instructions += StoreIndexed(kArrayCid);
38013807
}
38023808

38033809
const Class& factory_class =

0 commit comments

Comments
 (0)