Skip to content

Commit 9c56310

Browse files
committed
get_entry without building entries
1 parent 551b0f9 commit 9c56310

File tree

1 file changed

+5
-5
lines changed
  • sdk/pinocchio/src/sysvars/slot_hashes

1 file changed

+5
-5
lines changed

sdk/pinocchio/src/sysvars/slot_hashes/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,25 +191,25 @@ impl<T: Deref<Target = [u8]>> SlotHashes<T> {
191191
/// the slice is big enough and properly aligned.
192192
#[inline(always)]
193193
pub fn entries(&self) -> &[SlotHashEntry] {
194-
let len = self.len();
195-
debug_assert!(self.data.len() >= NUM_ENTRIES_SIZE + len * ENTRY_SIZE);
196-
197194
unsafe {
198195
// SAFETY: The slice begins `NUM_ENTRIES_SIZE` bytes into `self.data`, which
199196
// is guaranteed by parse_and_validate_data() to have at least `len * ENTRY_SIZE`
200197
// additional bytes. The pointer is properly aligned for `SlotHashEntry` (which
201198
// a compile-time assertion ensures is alignment 1).
202199
from_raw_parts(
203200
self.data.as_ptr().add(NUM_ENTRIES_SIZE) as *const SlotHashEntry,
204-
len,
201+
self.len(),
205202
)
206203
}
207204
}
208205

209206
/// Gets a reference to the entry at `index` or `None` if out of bounds.
210207
#[inline(always)]
211208
pub fn get_entry(&self, index: usize) -> Option<&SlotHashEntry> {
212-
self.entries().get(index)
209+
if index >= self.len() {
210+
return None;
211+
}
212+
Some(unsafe { self.get_entry_unchecked(index) })
213213
}
214214

215215
/// Finds the hash for a specific slot using binary search.

0 commit comments

Comments
 (0)