revm_bytecode/legacy/
jump_map.rs1use bitvec::vec::BitVec;
2use primitives::hex;
3use std::{fmt::Debug, sync::Arc};
4
5#[derive(Clone, Default, PartialEq, Eq, Hash, Ord, PartialOrd)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct JumpTable(pub Arc<BitVec<u8>>);
9
10impl Debug for JumpTable {
11 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
12 f.debug_struct("JumpTable")
13 .field("map", &hex::encode(self.0.as_raw_slice()))
14 .finish()
15 }
16}
17
18impl JumpTable {
19 #[inline]
21 pub fn as_slice(&self) -> &[u8] {
22 self.0.as_raw_slice()
23 }
24
25 #[inline]
27 pub fn from_slice(slice: &[u8]) -> Self {
28 Self(Arc::new(BitVec::from_slice(slice)))
29 }
30
31 #[inline]
33 pub fn is_valid(&self, pc: usize) -> bool {
34 pc < self.0.len() && unsafe { *self.0.get_unchecked(pc) }
35 }
36}