diff options
| author | Arpad Borsos <arpad.borsos@sentry.io> | 2024-02-15 12:00:34 +0100 |
|---|---|---|
| committer | Arpad Borsos <arpad.borsos@sentry.io> | 2024-02-15 12:00:34 +0100 |
| commit | 8eaaa6e610d92e2b29ef1cf46a796cc27c96428d (patch) | |
| tree | abf85c35ef8f56eb7f0f191846b38f7a11649791 | |
| parent | bd6b3361339522cc258d1f4165e3340e4cb1add4 (diff) | |
| download | rust-8eaaa6e610d92e2b29ef1cf46a796cc27c96428d.tar.gz rust-8eaaa6e610d92e2b29ef1cf46a796cc27c96428d.zip | |
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.
| -rw-r--r-- | library/core/src/char/methods.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index a93b94867ce..65ae4831839 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -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) } /// Returns `true` if this `char` has one of the general categories for numbers. |
