Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: skip visiting if it's out of range (vercel/turborepo#3762)
Visiting is not necessary for those sub-trees that are already out of range. ## The first code change For example, we have visitors with `ast_path` like this, and the current index is `1`, and the current path is `Path::A`: ```rust enum Path { A, B, C, D, E } visitors: vec![(vec![Path::B, Path::C], visitor), (vec![Path::B, Path::D], visitor)] ``` Given the fact that sub-trees that are not matched were already skipped, so there is no possibility for us to have things like this if we are already under `Path::B` and looking for the next path (`ast_path: [Path::B]`): ```rust visitors: vec![(vec![Path::B, Path::C], visitor), (vec![Path::C, Path::A], visitor)] ``` Combining all the things above, we can skip visits any furthur where its `kind` is greater than the `kind` for the current index, for the first example, the underlying path is `Path::A`, we can skip the sub-tree `Path::C` and `Path::D` as there's no possibility for the visitor subscribers to do with them. ## The second code change If the starting point for the partition result is already greater than the underlying `kind`, it's not necessary for us to visit them too.
- Loading branch information