Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(transformer/arrow-functions): use
NonEmptyStack
instead of `St…
…ack` (#8318) Follow-on after #8024. Use `NonEmptyStack` instead of `Stack`. `NonEmptyStack` is cheaper as `last` / `last_mut` always returns `T`, rather than `Option<T>`, so there's no need to branch on whether it's `Some` or not. The only downside of `NonEmptyStack` is that it always contains 1 dummy entry at the start (so that it's never empty). This means that it always allocates, unlike `Stack` which doesn't allocate unless you push something into it. So `NonEmptyStack` is always the better choice unless either: 1. The stack will likely never have anything pushed to it. or 2. The type the stack holds is large or expensive to construct, so there's a high cost in having to create an initial dummy value. In this case: * The type is `bool` - very small and cheap to construct. * The stack will be pushed to when entering a function. Very few JS files contain no functions at all, so the stack will always need to allocate, even if we used `Stack`. So this case doesn't satisfy either of the circumstances in which `Stack` is the better choice.
- Loading branch information