Skip to content

Commit

Permalink
minor slicer optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Jan 5, 2025
1 parent 254dcbd commit 9af9016
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions parser/src/earley/slicer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl SlicedBiasComputer {
tokens.push(vec![]);
}
}
mask.trim_trailing_zeros();
}

let entry = TokenizerSlice {
Expand Down
13 changes: 12 additions & 1 deletion toktrie/src/svob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,23 @@ impl SimpleVob {
}

pub fn or(&mut self, other: &SimpleVob) {
assert_eq!(self.size, other.size);
assert!(self.size >= other.size);
for (idx, v) in self.data.iter_mut().zip(other.data.iter()) {
*idx |= *v;
}
}

pub fn trim_trailing_zeros(&mut self) {
let mut idx = self.data.len();
while idx > 0 && self.data[idx - 1] == 0 {
idx -= 1;
}
if self.data.len() != idx {
self.data.truncate(idx);
self.size = self.data.len() * BITS;
}
}

/// self |= other & !minus
pub fn or_minus(&mut self, other: &SimpleVob, minus: &SimpleVob) {
assert_eq!(self.size, other.size);
Expand Down

0 comments on commit 9af9016

Please sign in to comment.