Skip to content

skip_whitespace is inefficient for non-whitespace tokens #209

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

Closed
jdm opened this issue Dec 8, 2017 · 5 comments
Closed

skip_whitespace is inefficient for non-whitespace tokens #209

jdm opened this issue Dec 8, 2017 · 5 comments

Comments

@jdm
Copy link
Member

jdm commented Dec 8, 2017

Depending on how often we call skip_whitespace when non-whitespace tokens are expected (which is actually quite common, IIRC) we can probably make it more efficient by adding a case to the top of the match at https://github.com/servo/rust-cssparser/blob/master/src/tokenizer.rs#L459 that catches any byte after / and immediately returns.

@SimonSapin
Copy link
Member

Line 459 is currently b' ' | b'\t' => {, I don’t understand what you mean by "any byte after /".

@jdm
Copy link
Member Author

jdm commented Dec 8, 2017

I mean that / has the highest ascii value, so any byte value greater than it is clearly not whitespace. Adding a check for that case before any other might be more efficient.

@SimonSapin
Copy link
Member

Oh I see. So something like byte if byte > b'/' => return, ?

@jdm
Copy link
Member Author

jdm commented Dec 8, 2017

Yeah.

@emilio
Copy link
Member

emilio commented Aug 2, 2023

We use match_byte for this now, which uses a lookup table, which seems to perform well

@emilio emilio closed this as completed Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants