Skip to content

Commit

Permalink
Merge 3e5cb84 into ebc49f6
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Feb 13, 2023
2 parents ebc49f6 + 3e5cb84 commit 709736a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/turbopack-ecmascript/src/path_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,29 @@ fn find_range<'a, 'b>(
index: usize,
) -> Option<&'b [(&'a AstPath, &'a dyn VisitorFactory)]> {
// Precondition: visitors is never empty
let start = if visitors.first().unwrap().0[index] >= *kind {
// Fast path: It's likely that the whole range is selected
if visitors.first().unwrap().0[index] > *kind || visitors.last().unwrap().0[index] < *kind {
// Fast path: If ast path of the first visitor is already out of range, then we
// can skip the whole visit.
return None;
}

let start = if visitors.first().unwrap().0[index] == *kind {
// Fast path: It looks like the whole range is selected
0
} else {
visitors.partition_point(|(path, _)| path[index] < *kind)
};

if start >= visitors.len() {
return None;
}

if visitors[start].0[index] > *kind {
// Fast path: If the starting point is greater than the given kind, it's
// meaningless to visit later.
return None;
}

let end = if visitors.last().unwrap().0[index] == *kind {
// Fast path: It's likely that the whole range is selected
visitors.len()
Expand Down

0 comments on commit 709736a

Please sign in to comment.