Skip to content

Commit e683624

Browse files
authored
outline cold path of lookup_ingredient
1 parent 0656eca commit e683624

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/zalsa.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,7 @@ impl Zalsa {
255255
/// Returns the ingredient at the given index, or panics if it is out-of-bounds.
256256
#[inline]
257257
pub fn lookup_ingredient(&self, index: IngredientIndex) -> &dyn Ingredient {
258-
let index = index.as_u32() as usize;
259-
self.ingredients_vec
260-
.get(index)
261-
.unwrap_or_else(|| panic!("index `{index}` is uninitialized"))
262-
.as_ref()
258+
self.ingredients_vec[index.as_u32() as usize].as_ref()
263259
}
264260

265261
/// Returns the ingredient at the given index.
@@ -269,10 +265,8 @@ impl Zalsa {
269265
/// The index must be in-bounds.
270266
#[inline]
271267
pub unsafe fn lookup_ingredient_unchecked(&self, index: IngredientIndex) -> &dyn Ingredient {
272-
let index = index.as_u32() as usize;
273-
274268
// SAFETY: Guaranteed by caller.
275-
unsafe { self.ingredients_vec.get_unchecked(index).as_ref() }
269+
unsafe { self.ingredients_vec.get_unchecked(index.as_u32() as usize).as_ref() }
276270
}
277271

278272
pub(crate) fn ingredient_index_for_memo(

0 commit comments

Comments
 (0)