Skip to content

Commit

Permalink
avm2: Remove unnecessary range checks on local-modifying ops in optim…
Browse files Browse the repository at this point in the history
…izer
  • Loading branch information
Lord-McSweeney authored and Lord-McSweeney committed Mar 23, 2024
1 parent 83f81c2 commit 4223006
Showing 1 changed file with 11 additions and 37 deletions.
48 changes: 11 additions & 37 deletions core/src/avm2/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,8 @@ impl<'gc> Locals<'gc> {
self.0[index] = value;
}

fn at(&self, index: usize) -> Option<OptValue<'gc>> {
self.0.get(index).copied()
}

fn len(&self) -> usize {
self.0.len()
fn at(&self, index: usize) -> OptValue<'gc> {
self.0[index]
}
}

Expand Down Expand Up @@ -242,20 +238,14 @@ pub fn optimize<'gc>(
| Op::IncLocalI { index }
| Op::DecLocal { index }
| Op::DecLocalI { index } => {
if (*index as usize) < initial_local_types.len() {
initial_local_types.set_any(*index as usize);
}
initial_local_types.set_any(*index as usize);
}
Op::HasNext2 {
object_register,
index_register,
} => {
if (*object_register as usize) < initial_local_types.len() {
initial_local_types.set_any(*object_register as usize);
}
if (*index_register as usize) < initial_local_types.len() {
initial_local_types.set_any(*index_register as usize);
}
initial_local_types.set_any(*object_register as usize);
initial_local_types.set_any(*index_register as usize);
}
_ => {}
}
Expand Down Expand Up @@ -384,14 +374,10 @@ pub fn optimize<'gc>(
stack.push_any();
}
Op::DecLocalI { index } => {
if (*index as usize) < local_types.len() {
local_types.set_any(*index as usize);
}
local_types.set_any(*index as usize);
}
Op::IncLocalI { index } => {
if (*index as usize) < local_types.len() {
local_types.set_any(*index as usize);
}
local_types.set_any(*index as usize);
}
Op::Increment => {
stack.pop();
Expand Down Expand Up @@ -605,27 +591,15 @@ pub fn optimize<'gc>(
}
}
Op::Kill { index } => {
if (*index as usize) < local_types.len() {
local_types.set_any(*index as usize);
}
local_types.set_any(*index as usize);
}
Op::SetLocal { index } => {
let stack_value = stack.pop();
if (*index as usize) < local_types.len() {
if let Some(stack_value) = stack_value {
local_types.set(*index as usize, stack_value);
} else {
local_types.set_any(*index as usize);
}
}
let stack_value = stack.pop_or_any();
local_types.set(*index as usize, stack_value);
}
Op::GetLocal { index } => {
let local_type = local_types.at(*index as usize);
if let Some(local_type) = local_type {
stack.push(local_type);
} else {
stack.push_any();
}
stack.push(local_type);
}
Op::GetLex { .. } => {
stack.push_any();
Expand Down

0 comments on commit 4223006

Please sign in to comment.