aboutsummaryrefslogtreecommitdiffstats
path: root/src/tokenizer.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-22 18:31:21 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-22 18:31:21 +0200
commit0525454e33ed6bcd7b43da1c0969c1d592e743d9 (patch)
tree9e1565860b72b7a35370260ec4a683811b55299b /src/tokenizer.rs
parent002b6bfb54eebc70a9b5e9fb62175777044c9338 (diff)
downloadmarkdown-rs-0525454e33ed6bcd7b43da1c0969c1d592e743d9.tar.gz
markdown-rs-0525454e33ed6bcd7b43da1c0969c1d592e743d9.tar.bz2
markdown-rs-0525454e33ed6bcd7b43da1c0969c1d592e743d9.zip
Refactor to reserve some more vecs
Diffstat (limited to '')
-rw-r--r--src/tokenizer.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index bb73430..685198e 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -253,8 +253,9 @@ impl<'a> Tokenizer<'a> {
concrete: false,
lazy: false,
container: None,
- resolvers: vec![],
- resolver_ids: vec![],
+ // Assume about 10 resolvers.
+ resolvers: Vec::with_capacity(10),
+ resolver_ids: Vec::with_capacity(10)
}
}
@@ -479,7 +480,7 @@ impl<'a> Tokenizer<'a> {
if matches!(state, State::Ok(_)) {
feed_impl(tokenizer, result.1, after)
} else {
- State::Nok
+ state
}
},
)
@@ -491,7 +492,7 @@ impl<'a> Tokenizer<'a> {
pub fn go_until(
&mut self,
state_fn: impl FnOnce(&mut Tokenizer, Code) -> State + 'static,
- until: impl FnMut(Code) -> bool + 'static,
+ until: impl Fn(Code) -> bool + 'static,
done: impl FnOnce(State) -> Box<StateFn> + 'static,
) -> Box<StateFn> {
attempt_impl(
@@ -620,6 +621,9 @@ impl<'a> Tokenizer<'a> {
) -> State {
assert!(!self.drained, "cannot feed after drain");
+ // Let’s assume an event per character.
+ self.events.reserve(codes.len());
+
let mut result = feed_impl(self, codes, start);
if drain {
@@ -667,7 +671,7 @@ impl<'a> Tokenizer<'a> {
/// Used in [`Tokenizer::attempt`][Tokenizer::attempt] and [`Tokenizer::check`][Tokenizer::check].
fn attempt_impl(
state: impl FnOnce(&mut Tokenizer, Code) -> State + 'static,
- mut pause: impl FnMut(Code) -> bool + 'static,
+ pause: impl Fn(Code) -> bool + 'static,
mut codes: Vec<Code>,
done: impl FnOnce((&[Code], &[Code]), &mut Tokenizer, State) -> State + 'static,
) -> Box<StateFn> {