Skip to content
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

Remove duplicated code to detect Rust keywords/identifiers #24

Merged
merged 1 commit into from
Jun 23, 2024

Conversation

GuillaumeGomez
Copy link
Contributor

Follow-up of #23.

cc @Kijewski

// Since the individual buckets are quite short, a linear search is faster than a binary search.
kws[ident_len]
.iter()
.any(|&probe| padded_ident == &probe[2..])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting! You are right, the

padded_ident == <[u8; parser::node::MAX_KW_LEN]>::try_from(&probe[2..]).unwrap()

"optimization" is not needed anymore, and now the same code generated with and without it. When I first wrote the search, it was still needed because otherwise the assembly would needlessly contain length checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh interesting. I checked and couldn't find out why it was needed. I suppose rustc/LLVM got better.

Copy link
Collaborator

@Kijewski Kijewski left a comment

Choose a reason for hiding this comment

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

Thanks you!

@Kijewski Kijewski merged commit 4e88a30 into rinja-rs:master Jun 23, 2024
16 checks passed
@GuillaumeGomez GuillaumeGomez deleted the simplify-kws branch June 23, 2024 13:06
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