Skip to content

Commit c868f3f

Browse files
committed
optimization: Don't include ASCII characters in Unicode tables
The ASCII subset of Unicode is fixed and will never change, so we don't need to generate tables for it with every new Unicode version. This saves a few bytes of static data and speeds up `char::is_control` and `char::is_grapheme_extended` on ASCII inputs.
1 parent 3a75193 commit c868f3f

File tree

6 files changed

+293
-247
lines changed

6 files changed

+293
-247
lines changed

library/core/src/char/methods.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ impl char {
950950
#[stable(feature = "rust1", since = "1.0.0")]
951951
#[inline]
952952
pub fn is_control(self) -> bool {
953-
unicode::Cc(self)
953+
if self.is_ascii() { self.is_ascii_control() } else { unicode::Cc(self) }
954954
}
955955

956956
/// Returns `true` if this `char` has the `Grapheme_Extend` property.
@@ -965,7 +965,7 @@ impl char {
965965
#[must_use]
966966
#[inline]
967967
pub(crate) fn is_grapheme_extended(self) -> bool {
968-
unicode::Grapheme_Extend(self)
968+
!self.is_ascii() && unicode::Grapheme_Extend(self)
969969
}
970970

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

0 commit comments

Comments
 (0)