Skip to content

Commit bdde2a8

Browse files
committedMar 5, 2024·
Auto merge of #121138 - Swatinem:grapheme-extend-ascii, r=cuviper
Add ASCII fast-path for `char::is_grapheme_extended` I discovered that `impl Debug for str` is quite slow because it ends up doing a `unicode_data::grapheme_extend::lookup` for each char, which ends up doing a binary search. This introduces a fast-path for ASCII chars which do not have this property. The `lookup` is thus completely gone from profiles. --- As a followup, maybe it’s worth implementing this fast path directly in `unicode_data` so that it can check for the lower bound directly before going to a potentially expensive binary search.
2 parents 41d97c8 + 8eaaa6e commit bdde2a8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎library/core/src/char/methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ impl char {
927927
#[must_use]
928928
#[inline]
929929
pub(crate) fn is_grapheme_extended(self) -> bool {
930-
unicode::Grapheme_Extend(self)
930+
self > '\x7f' && unicode::Grapheme_Extend(self)
931931
}
932932

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

0 commit comments

Comments
 (0)
Please sign in to comment.