avm2: Optimize unnecessary `Coerce` when it comes after `PushString`, `NewArray`, and `NewFunction`

This commit is contained in:
Lord-McSweeney 2024-01-07 17:58:04 -08:00 committed by Lord-McSweeney
parent f99c5621ee
commit dd82126448
1 changed files with 32 additions and 1 deletions

View File

@ -760,7 +760,14 @@ fn optimize<'gc>(
) && !GcCell::ptr_eq(
class,
activation.avm2().classes().void.inner_class_definition(),
) && !GcCell::ptr_eq(
) {
previous_op = Some(op.clone());
*op = Op::Nop;
continue;
}
}
Op::PushString { .. } => {
if GcCell::ptr_eq(
class,
activation.avm2().classes().string.inner_class_definition(),
) {
@ -769,6 +776,30 @@ fn optimize<'gc>(
continue;
}
}
Op::NewArray { .. } => {
if GcCell::ptr_eq(
class,
activation.avm2().classes().array.inner_class_definition(),
) {
previous_op = Some(op.clone());
*op = Op::Nop;
continue;
}
}
Op::NewFunction { .. } => {
if GcCell::ptr_eq(
class,
activation
.avm2()
.classes()
.function
.inner_class_definition(),
) {
previous_op = Some(op.clone());
*op = Op::Nop;
continue;
}
}
Op::Coerce {
index: previous_name_index,
} => {