Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parser performance issues #307

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 31 additions & 33 deletions crates/mun_syntax/src/parsing/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,43 @@ impl Event {
pub(super) fn process(sink: &mut dyn TreeSink, mut events: Vec<Event>) {
let mut forward_parents = Vec::new();

for _i in 0..events.len() {
for i in 0..events.len() {
match mem::replace(&mut events[i], Event::tombstone()) {
Event::Start {
kind: TOMBSTONE, ..
} => (),
Event::Start {
kind,
forward_parent,
} => {
forward_parents.push(kind);
let mut idx = i;
let mut fp = forward_parent;
while let Some(fwd) = fp {
idx += fwd as usize;
fp = match mem::replace(&mut events[idx], Event::tombstone()) {
Event::Start {
kind,
forward_parent,
} => {
if kind != TOMBSTONE {
forward_parents.push(kind);
}
forward_parent
for i in 0..events.len() {
match mem::replace(&mut events[i], Event::tombstone()) {
Event::Start {
kind: TOMBSTONE, ..
} => (),
Event::Start {
kind,
forward_parent,
} => {
forward_parents.push(kind);
let mut idx = i;
let mut fp = forward_parent;
while let Some(fwd) = fp {
idx += fwd as usize;
fp = match mem::replace(&mut events[idx], Event::tombstone()) {
Event::Start {
kind,
forward_parent,
} => {
if kind != TOMBSTONE {
forward_parents.push(kind);
}
_ => unreachable!(),
forward_parent
}
}

for kind in forward_parents.drain(..).rev() {
sink.start_node(kind)
_ => unreachable!(),
}
}
Event::Finish => sink.finish_node(),
Event::Token { kind, n_raw_tokens } => {
sink.token(kind, n_raw_tokens);

for kind in forward_parents.drain(..).rev() {
sink.start_node(kind)
}
Event::Error { msg } => sink.error(msg),
}
Event::Finish => sink.finish_node(),
Event::Token { kind, n_raw_tokens } => {
sink.token(kind, n_raw_tokens);
}
Event::Error { msg } => sink.error(msg),
}
}
}