#2439 made using `continue_if` in `byte_search!` macro safe, as it no longer continues the main loop after a match, so no danger of reading out of bounds if `continue_if` code fast-forwards the current position.
This follow-on PR removes the unsafe blocks, and uses that fast-forward ability in a couple of places.
Refactor `byte_search!` macro to move logic out of the main loop. This ensures the compiler unrolls the loop.
This speeds up lexing single-line comments by 20%-25% on the benchmarks which contain enough comments for the change to register. Presumably the loop wasn't unrolled previously.
The code required to do this is a little odd. It adds an extra `loop {}` which always exits on the first turn (so not really a useful loop), but is required to be able to use `break` to exit that "loop", making 2 different paths for (1) matching byte found and (2) `for` loop completed without finding any match.
This is only way I could find to produce this behavior without using a macro. Is there a more "normal" way to get the same logic?
Catch all illegal UTF-8 bytes with the `UER` byte handler.
From https://datatracker.ietf.org/doc/html/rfc3629:
> The octet values C0, C1, F5 to FF never appear.
This change *should* make no difference at all, as a valid `&str` may not contain any of these byte values anyway. But it's possible if user has e.g. created the string with `str::from_utf8_unchecked` and not obeyed the safety contraints. This will at least contain the damage if that's happened, and panic rather than lead to UB. And since we're already catching other error conditions, may as well catch them all.
Fixes#2360
To make `jsx-a11y/anchor-has-content` test pass,
- [x] Use `utils::get_element_type(ctx, el)` in
`utils::is_hidden_from_screen_reader` and
`utils::object_has_accessible_child`
- [x] `utils::object_has_accessible_child` should handle both `null` and
`undefined`
and on the way...,
- [x] `utils::get_element_type` should be used only in `jsx_a11y/*`
rules
- [x] Use those utils everywhere(remove manual implementation)
The runtime performance gains does not out weight the compilation speed from
building the custom allocators, which takes about a minute to build on
slower machines.
Consume multi-line comments faster.
* Initially search for `*/`, `\r`, `\n` or `0xE2` (first byte of
irregular line breaks).
* Once a line break is found, switch to faster search which only looks
for `*/`, as it's not relevant whether there are more line breaks or
not.
Using `memchr` for the 2nd simpler search, as it's efficient for a
search with only one "needle".
Initializing `memchr::memmem::Finder` is fairly expensive, and tried
numerous ways to handle it. This is most performant way I could find.
Any ideas how to avoid re-creating it for each Lexer pass? (it can't be
a `static` as `Finder::new` is not a const function, and `lazy_static!`
is too costly)