Skip to content

Commit 25c852b

Browse files
committed
chore: simplify jit branch type casting
1 parent f3bddb3 commit 25c852b

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

ristretto_jit/src/instruction/branch.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ pub(crate) fn tableswitch(
579579
let mut switch = Switch::new();
580580

581581
for (offset_index, &offset) in table_switch.offsets.iter().enumerate() {
582-
let target_address =
583-
usize::try_from(i32::try_from(program_counter)?.saturating_add(offset))?;
582+
let target_address = program_counter.saturating_add(usize::try_from(offset)?);
584583
let target_block = *blocks
585584
.get(&target_address)
586585
.ok_or_else(|| InvalidBlockAddress(target_address))?;
@@ -590,8 +589,7 @@ pub(crate) fn tableswitch(
590589
switch.set_entry(case_value, target_block);
591590
}
592591

593-
let default_address =
594-
usize::try_from(i32::try_from(program_counter)?.saturating_add(table_switch.default))?;
592+
let default_address = program_counter.saturating_add(usize::try_from(table_switch.default)?);
595593
let default_block = *blocks
596594
.get(&default_address)
597595
.ok_or_else(|| InvalidBlockAddress(default_address))?;
@@ -615,8 +613,7 @@ pub(crate) fn lookupswitch(
615613
let mut switch = Switch::new();
616614

617615
for (case_value, offset) in &lookup_switch.pairs {
618-
let target_address =
619-
usize::try_from(i32::try_from(program_counter)?.saturating_add(*offset))?;
616+
let target_address = program_counter.saturating_add(usize::try_from(*offset)?);
620617
let target_block = *blocks
621618
.get(&target_address)
622619
.ok_or_else(|| InvalidBlockAddress(target_address))?;
@@ -625,8 +622,7 @@ pub(crate) fn lookupswitch(
625622
switch.set_entry(case_value, target_block);
626623
}
627624

628-
let default_address =
629-
usize::try_from(i32::try_from(program_counter)?.saturating_add(lookup_switch.default))?;
625+
let default_address = program_counter.saturating_add(usize::try_from(lookup_switch.default)?);
630626
let default_block = *blocks
631627
.get(&default_address)
632628
.ok_or_else(|| InvalidBlockAddress(default_address))?;

0 commit comments

Comments
 (0)