Skip to content

Commit f534c13

Browse files
committed
[dart2js, ddc] Slightly quicker 'as' checks for primitve types
We have special methods in the rti library for checks like `as int` and `as String?`. dart2js uses these when the type is known. This change installs them on the `_as` property, so that we get a small performance boost from calling a direct method rather than the `_as` method calling the `_is` method. Change-Id: Ia40a2fc7791f38590655a9b249fd9c36fb45369e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407604 Reviewed-by: Nicholas Shahan <[email protected]>
1 parent 81f7324 commit f534c13

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sdk/lib/_internal/js_shared/lib/rti.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,29 @@ Object? _installSpecializedAsCheck(Object? object) {
14411441
isNullable(testRti)) {
14421442
asFn = RAW_DART_FUNCTION_REF(_generalNullableAsCheckImplementation);
14431443
}
1444+
if (!JS_GET_FLAG('LEGACY')) {
1445+
if (_Utils.isIdentical(testRti, TYPE_REF<int>())) {
1446+
asFn = RAW_DART_FUNCTION_REF(_asInt);
1447+
} else if (_Utils.isIdentical(testRti, TYPE_REF<int?>())) {
1448+
asFn = RAW_DART_FUNCTION_REF(_asIntQ);
1449+
} else if (_Utils.isIdentical(testRti, TYPE_REF<String>())) {
1450+
asFn = RAW_DART_FUNCTION_REF(_asString);
1451+
} else if (_Utils.isIdentical(testRti, TYPE_REF<String?>())) {
1452+
asFn = RAW_DART_FUNCTION_REF(_asStringQ);
1453+
} else if (_Utils.isIdentical(testRti, TYPE_REF<bool>())) {
1454+
asFn = RAW_DART_FUNCTION_REF(_asBool);
1455+
} else if (_Utils.isIdentical(testRti, TYPE_REF<bool?>())) {
1456+
asFn = RAW_DART_FUNCTION_REF(_asBoolQ);
1457+
} else if (_Utils.isIdentical(testRti, TYPE_REF<num>())) {
1458+
asFn = RAW_DART_FUNCTION_REF(_asNum);
1459+
} else if (_Utils.isIdentical(testRti, TYPE_REF<num?>())) {
1460+
asFn = RAW_DART_FUNCTION_REF(_asNumQ);
1461+
} else if (_Utils.isIdentical(testRti, TYPE_REF<double>())) {
1462+
asFn = RAW_DART_FUNCTION_REF(_asDouble);
1463+
} else if (_Utils.isIdentical(testRti, TYPE_REF<double?>())) {
1464+
asFn = RAW_DART_FUNCTION_REF(_asDoubleQ);
1465+
}
1466+
}
14441467

14451468
Rti._setAsCheckFunction(testRti, asFn);
14461469
return Rti._asCheck(testRti, object);

0 commit comments

Comments
 (0)