FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

tokenizer: Make consume_name faster. by emilio · Pull Request #449 · servo/rust-cssparser · GitHub

tokenizer: Make consume_name faster. - #449

Merged
emilio merged 1 commit into
mainfrom
consume-name-fast
Aug 28, 2026
Merged

tokenizer: Make consume_name faster.#449
emilio merged 1 commit into
mainfrom
consume-name-fast

Conversation

emilio commented Aug 28, 2026

Copy link
Copy Markdown
Member

Skip over runs of ascii and such in a tight loop. This is one of the hottest functions and match_byte! adds extra branches for the common cases.

Skip over runs of ascii and such in a tight loop. This is one of the
hottest functions and match_byte! adds extra branches for the common
cases.

nicoburns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks correct to me

Comment thread src/tokenizer.rs
Comment on lines +950 to +959
// These are the overwhelmingly common bytes, that we can just skip over in a tight loop.
static IS_SIMPLE_NAME_BYTE: [bool; 256] = {
let mut table = [false; 256];
let mut i = 0;
while i < 256 {
table[i as usize] = matches!(i as u8, b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' | b'_' | b'-' | b'\xC0'..=b'\xEF');
i += 1;
}
table
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Given that this is a table of bool you could also try a bitset, and see if that's any faster.

Comment thread src/tokenizer.rs

// start_pos is the end of the previous token, therefore at a code point boundary
let start_pos = tokenizer.position();
let mut value_bytes;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nit: an explicit type annotation on value_bytes would nice.

emilio added this pull request to the merge queue Aug 28, 2026
Merged via the queue into main with commit 9b3fbd4 Aug 28, 2026
14 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL