starting to optimizing position
@@ -278,14 +278,12 @@ impl<'i> Position<'i> {
for from in self.pos..self.input.len() {
for slice in strings.iter() {
let to = from + slice.len();
- if let Some(t) = self.input.get(from..to) {
- if t == *slice {
+ if slice.as_bytes() == &self.input.as_bytes()[from..to] {
self.pos = from;
return true;
}
}
}
- }
self.pos = self.input.len();
false
@@ -315,16 +313,12 @@ impl<'i> Position<'i> {
pub(crate) fn match_string(&mut self, string: &str) -> bool {
let to = self.pos + string.len();
- if let Some(slice) = self.input.get(self.pos..to) {
- if string == slice {
+ if Some(string) == self.input.get(self.pos..to) {
self.pos += string.len();
true
} else {
false
}
- } else {
- false
- }
}
/// Case-insensitively matches `string` from the `Position` and returns `true` if a match was
