mirror of
https://github.com/aphrody-labs/oxc.git
synced 2026-10-17 21:07:02 +00:00
perf(packages/codegen): reduce megamorphic type reads in printConditionalExpression (#27591)
Perf optimization. Continuation of [#27458](https://github.com/oxc-project/oxc/issues/27458). The test of a conditional expression can be any expression, so reading its `type` is a megamorphic load (a builtin call, which V8 does not deduplicate). In TS builds, read its `type` once while unwrapping parens, instead of in `withoutParens` and again after it.
This commit is contained in:
1 parent
a9bd9420d4
commit
256259ddfa
1 file changed
+7
-1
@@ -770,7 +770,13 @@ function printConditionalExpression(
|
||||
// round trip: `value as Type ? /x/ : y` re-lexes the `/` as a division.
|
||||
let testPrecedence = PREC_CONDITIONAL;
|
||||
if (TS) {
|
||||
const testType = withoutParens(node.test).type;
|
||||
let { test } = node;
|
||||
let testType = test.type;
|
||||
while (testType === "ParenthesizedExpression") {
|
||||
test = (test as ESTree.ParenthesizedExpression).expression;
|
||||
testType = test.type;
|
||||
}
|
||||
|
||||
if (testType === "TSAsExpression" || testType === "TSSatisfiesExpression") {
|
||||
testPrecedence = PREC_COMPARE;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user