Skip to content

Commit

Permalink
Shorten const_idx().
Browse files Browse the repository at this point in the history
  • Loading branch information
vext01 committed Feb 21, 2024
1 parent 920752c commit 2e7e014
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions ykrt/src/compile/jitc_yk/jit_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,14 +732,12 @@ impl Module {
/// Get the index of a constant, inserting it in the constant table if necessary.
pub fn const_idx(&mut self, c: &Constant) -> Result<ConstIdx, CompilationError> {
// FIXME: can we optimise this?
for (idx, tc) in self.consts.iter().enumerate() {
if tc == c {
// const table hit.
return ConstIdx::new(idx);
}
if let Some(idx) = self.consts.iter().position(|tc| tc == c) {
Ok(ConstIdx::new(idx)?)
} else {
// const table miss, we need to insert it.
self.push_const(c.clone())
}
// const table miss, we need to insert it.
self.push_const(c.clone())
}

/// Get the index of a type, inserting it into the type table if necessary.
Expand Down

0 comments on commit 2e7e014

Please sign in to comment.