Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1025c5b

Browse files
askeksacommit-bot@chromium.org
authored andcommitted
[DDC] Only inline textually small constants.
Fixes dart-lang/sdk#36535 Change-Id: I62ad6d6f7390284d0a7a52d0d4b31e57ea1fbea6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103623 Reviewed-by: Vijay Menon <[email protected]> Commit-Queue: Aske Simon Christensen <[email protected]>
1 parent 25033ce commit 1025c5b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/dev_compiler/lib/src/kernel/constants.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ class DevCompilerConstantsBackend extends ConstantsBackend {
200200

201201
@override
202202
NumberSemantics get numberSemantics => NumberSemantics.js;
203+
204+
@override
205+
bool shouldInlineConstant(ConstantExpression initializer) {
206+
Constant constant = initializer.constant;
207+
if (constant is StringConstant) {
208+
// Only inline small string constants, not large ones.
209+
// (The upper bound value is arbitrary.)
210+
return constant.value.length < 32;
211+
} else if (constant is PrimitiveConstant) {
212+
// Inline all other primitives.
213+
return true;
214+
} else {
215+
// Don't inline other constants, because it would take too much code size.
216+
// Better to refer to them by their field/variable name.
217+
return false;
218+
}
219+
}
203220
}
204221

205222
class _ErrorReporter extends SimpleErrorReporter {

0 commit comments

Comments
 (0)