/// A fixed-size array-like vector of hashes with maximum capacity of 256. /// Used instread of Vec<Hash> to avoid heap allocations. pub(crate) type TokensBuffer = ArrayVec<Hash, 256>;
fn fast_tokenizer_no_regex(
pattern: &str,
is_allowed_code: &dynFn(char) -> bool,
skip_first_token: bool,
skip_last_token: bool,
tokens_buffer: &mut TokensBuffer,
) { // let mut tokens_buffer_index = 0; letmut inside: bool = false; letmut start = 0; letmut preceding_ch: Option<char> = None; // Used to check if a '*' is not just before a token
for (i, c) in pattern.char_indices() { if tokens_buffer.capacity() - tokens_buffer.len() <= 1 { return; // reserve one free slot for the zero token
} if is_allowed_code(c) { if !inside {
inside = true;
start = i;
}
} elseif inside {
inside = false; // Should not be followed by '*' if (start != 0 || !skip_first_token)
&& i - start > 1
&& c != '*'
&& preceding_ch != Some('*')
{ let hash = fast_hash(&pattern[start..i]);
tokens_buffer.push(hash);
}
preceding_ch = Some(c);
} else {
preceding_ch = Some(c);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.