diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-02 13:20:47 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-02 13:20:47 +0000 |
commit | 91bf5fa827b2c4ef74cb68c172c79127115e394f (patch) | |
tree | ebbd7ebb043fe9a8bee8ac2419a461c3387b1888 /crates/mbe/src/expander/transcriber.rs | |
parent | 8eee9149e87ea58d4191d04ebe6faf57ac8485a3 (diff) | |
parent | cff2201c30bda7b346e3b47875d95a2cf9cafaa3 (diff) |
Merge #7513
7513: NFA parser for mbe matcher r=matklad a=edwin0cheng
Almost straight porting from rustc one, but a little bit slow :(
```
rust-analyzer analysis-stats -q .
```
From:
```log
Database loaded: 636.11ms, 277minstr
crates: 36, mods: 594, decls: 11527, fns: 9017
Item Collection: 10.99s, 60ginstr
exprs: 249618, ??ty: 2699 (1%), ?ty: 2101 (0%), !ty: 932
Inference: 28.94s, 123ginstr
Total: 39.93s, 184ginstr
```
To:
```log
Database loaded: 630.90ms, 277minstr
crates: 36, mods: 594, decls: 11528, fns: 9018
Item Collection: 13.70s, 77ginstr
exprs: 249482, ??ty: 2699 (1%), ?ty: 2101 (0%), !ty: 932
Inference: 30.27s, 133ginstr
Total: 43.97s, 211ginstr
```
Fixes #4777
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/mbe/src/expander/transcriber.rs')
-rw-r--r-- | crates/mbe/src/expander/transcriber.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs index 78368a33e..ad9953a7d 100644 --- a/crates/mbe/src/expander/transcriber.rs +++ b/crates/mbe/src/expander/transcriber.rs | |||
@@ -13,13 +13,17 @@ use crate::{ | |||
13 | 13 | ||
14 | impl Bindings { | 14 | impl Bindings { |
15 | fn contains(&self, name: &str) -> bool { | 15 | fn contains(&self, name: &str) -> bool { |
16 | self.inner.contains_key(name) | 16 | self.inner.iter().any(|(n, _)| n == name) |
17 | } | 17 | } |
18 | 18 | ||
19 | fn get(&self, name: &str, nesting: &mut [NestingState]) -> Result<&Fragment, ExpandError> { | 19 | fn get(&self, name: &str, nesting: &mut [NestingState]) -> Result<&Fragment, ExpandError> { |
20 | let mut b = self.inner.get(name).ok_or_else(|| { | 20 | let mut b: &Binding = self |
21 | ExpandError::BindingError(format!("could not find binding `{}`", name)) | 21 | .inner |
22 | })?; | 22 | .iter() |
23 | .find_map(|(n, b)| if n == name { Some(b) } else { None }) | ||
24 | .ok_or_else(|| { | ||
25 | ExpandError::BindingError(format!("could not find binding `{}`", name)) | ||
26 | })?; | ||
23 | for nesting_state in nesting.iter_mut() { | 27 | for nesting_state in nesting.iter_mut() { |
24 | nesting_state.hit = true; | 28 | nesting_state.hit = true; |
25 | b = match b { | 29 | b = match b { |