Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abbiecnt committed Aug 26, 2024
1 parent e42ca27 commit fc0bfdf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod base;
mod pattern;
mod program;
mod section;

pub use base::*;
pub use pattern::*;
pub use program::*;
pub use section::*;
16 changes: 9 additions & 7 deletions src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Section {

impl Section {
#[inline]
pub fn name(&self) -> &'static str {
pub fn name(&self) -> &str {
self.name
}

Expand All @@ -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) })
}
}

0 comments on commit fc0bfdf

Please sign in to comment.