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

Add ASCII fast-path for char::is_grapheme_extended #121138

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ impl char {
#[must_use]
#[inline]
pub(crate) fn is_grapheme_extended(self) -> bool {
unicode::Grapheme_Extend(self)
self > '\x7f' && unicode::Grapheme_Extend(self)
Copy link
Contributor

@tgross35 tgross35 Mar 5, 2024

Choose a reason for hiding this comment

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

Any reason not to instead update unicode-table-generator so this becomes a part of Grapheme_Extend (unicode::unicode_data::grapheme_extended::lookup)? So as to help anywhere else this call might wind up getting used

Doesn't have to be part of this PR, maybe later refactoring

Copy link
Contributor

Choose a reason for hiding this comment

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

We really should have a const ASCII_MAX: char = '\x7f' somewhere, maybe even public. We throw that magic number around a lot

Copy link
Member

Choose a reason for hiding this comment

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

The generator doesn't know specifics about particular properties yet, AFAICS, but I could imagine it could generically optimize lookups outside of a property's min/max.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually did this in the unicode-table-generator (and fun fact: this was the only properly with a min > ASCII). Let me open that up as a PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here you go: #122013

}

/// Returns `true` if this `char` has one of the general categories for numbers.
Expand Down
Loading