mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Merge #5083
5083: Micro-optimize lookahead in composite tokens r=matklad a=lnicola I'm not sure that this is measurable, but can't hurt, I guess. Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
7488cd6a1b
@ -127,17 +127,24 @@ impl<'t> Parser<'t> {
|
|||||||
|
|
||||||
fn at_composite2(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind) -> bool {
|
fn at_composite2(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind) -> bool {
|
||||||
let t1 = self.token_source.lookahead_nth(n);
|
let t1 = self.token_source.lookahead_nth(n);
|
||||||
|
if t1.kind != k1 || !t1.is_jointed_to_next {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
let t2 = self.token_source.lookahead_nth(n + 1);
|
let t2 = self.token_source.lookahead_nth(n + 1);
|
||||||
t1.kind == k1 && t1.is_jointed_to_next && t2.kind == k2
|
t2.kind == k2
|
||||||
}
|
}
|
||||||
|
|
||||||
fn at_composite3(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind, k3: SyntaxKind) -> bool {
|
fn at_composite3(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind, k3: SyntaxKind) -> bool {
|
||||||
let t1 = self.token_source.lookahead_nth(n);
|
let t1 = self.token_source.lookahead_nth(n);
|
||||||
|
if t1.kind != k1 || !t1.is_jointed_to_next {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
let t2 = self.token_source.lookahead_nth(n + 1);
|
let t2 = self.token_source.lookahead_nth(n + 1);
|
||||||
|
if t2.kind != k2 || !t2.is_jointed_to_next {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
let t3 = self.token_source.lookahead_nth(n + 2);
|
let t3 = self.token_source.lookahead_nth(n + 2);
|
||||||
(t1.kind == k1 && t1.is_jointed_to_next)
|
t3.kind == k3
|
||||||
&& (t2.kind == k2 && t2.is_jointed_to_next)
|
|
||||||
&& t3.kind == k3
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the current token is in `kinds`.
|
/// Checks if the current token is in `kinds`.
|
||||||
|
Loading…
Reference in New Issue
Block a user