diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-26 20:25:46 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-26 20:25:46 +0100 |
commit | 7488cd6a1b3604d6b4f11a7f83b6006a34cda0c0 (patch) | |
tree | bd1d793159823b525efb359ddd352839fbe24c14 /crates | |
parent | e628c6635917cb9a280b435cc1cd55bc511ed770 (diff) | |
parent | 2c72d2f438fe0f8b1cbc41ac12e578a5817bafc4 (diff) |
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 <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_parser/src/parser.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs index 4f59b0a23..d797f2cc9 100644 --- a/crates/ra_parser/src/parser.rs +++ b/crates/ra_parser/src/parser.rs | |||
@@ -127,17 +127,24 @@ impl<'t> Parser<'t> { | |||
127 | 127 | ||
128 | fn at_composite2(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind) -> bool { | 128 | fn at_composite2(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind) -> bool { |
129 | let t1 = self.token_source.lookahead_nth(n); | 129 | let t1 = self.token_source.lookahead_nth(n); |
130 | if t1.kind != k1 || !t1.is_jointed_to_next { | ||
131 | return false; | ||
132 | } | ||
130 | let t2 = self.token_source.lookahead_nth(n + 1); | 133 | let t2 = self.token_source.lookahead_nth(n + 1); |
131 | t1.kind == k1 && t1.is_jointed_to_next && t2.kind == k2 | 134 | t2.kind == k2 |
132 | } | 135 | } |
133 | 136 | ||
134 | fn at_composite3(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind, k3: SyntaxKind) -> bool { | 137 | fn at_composite3(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind, k3: SyntaxKind) -> bool { |
135 | let t1 = self.token_source.lookahead_nth(n); | 138 | let t1 = self.token_source.lookahead_nth(n); |
139 | if t1.kind != k1 || !t1.is_jointed_to_next { | ||
140 | return false; | ||
141 | } | ||
136 | let t2 = self.token_source.lookahead_nth(n + 1); | 142 | let t2 = self.token_source.lookahead_nth(n + 1); |
143 | if t2.kind != k2 || !t2.is_jointed_to_next { | ||
144 | return false; | ||
145 | } | ||
137 | let t3 = self.token_source.lookahead_nth(n + 2); | 146 | let t3 = self.token_source.lookahead_nth(n + 2); |
138 | (t1.kind == k1 && t1.is_jointed_to_next) | 147 | t3.kind == k3 |
139 | && (t2.kind == k2 && t2.is_jointed_to_next) | ||
140 | && t3.kind == k3 | ||
141 | } | 148 | } |
142 | 149 | ||
143 | /// Checks if the current token is in `kinds`. | 150 | /// Checks if the current token is in `kinds`. |