diff --git a/src/lib.rs b/src/lib.rs index 0492c3a..ea0b9d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,7 @@ mod base; -mod pattern; mod program; mod section; pub use base::*; -pub use pattern::*; pub use program::*; pub use section::*; diff --git a/src/section.rs b/src/section.rs index 88b91cb..948ad95 100644 --- a/src/section.rs +++ b/src/section.rs @@ -12,7 +12,7 @@ pub struct Section { impl Section { #[inline] - pub fn name(&self) -> &'static str { + pub fn name(&self) -> &str { self.name } @@ -35,12 +35,14 @@ impl Section { pub fn find(&self, pattern: &[u8]) -> Option<*const u8> { self.as_slice() .par_windows(pattern.len()) - .position_first(|window| { - pattern - .iter() - .enumerate() - .all(|(index, &pattern)| window[index] == pattern) - }) + .position_first(|window| window == pattern) + .map(|offset| unsafe { self.as_ptr().add(offset) }) + } + + pub fn rfind(&self, pattern: &[u8]) -> Option<*const u8> { + self.as_slice() + .par_windows(pattern.len()) + .position_last(|window| window == pattern) .map(|offset| unsafe { self.as_ptr().add(offset) }) } }