Truly independent web browser
LibWeb: Skip the emoji property lookups for Latin code points
Andreas Kling731c6176207c
diff --git a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs b/Libraries/LibWeb/Rust/src/layout/text_chunker.rsindex 9105d02104d..1034be52a41 100644--- a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs+++ b/Libraries/LibWeb/Rust/src/layout/text_chunker.rs@@ -570,10 +570,34 @@ impl<'text> TextChunker<'text> {fn emoji_presentation_at(&self, code_unit_offset: usize, code_point: u32) -> EmojiPresentation {let next_offset = code_unit_offset + code_unit_length_for_code_point(code_point);let next_code_point = (next_offset < self.text.len()).then(|| code_point_at(self.text, next_offset));- let default_presentation = emoji_presentation_for_code_point(code_point, next_code_point);-- // SAFETY: Pure Unicode table lookup.- if default_presentation.forced || !unsafe { unicode_layout_code_point_has_emoji_property(code_point) } {+ // OPTIMIZATION: No code point below U+0300 has the Emoji_Presentation property, so only a variation selector+ // can give one of them anything but the default text presentation.+ let default_presentation = if code_point < 0x300 && !matches!(next_code_point, Some(0xfe0e | 0xfe0f)) {+ EmojiPresentation {+ is_emoji: false,+ forced: false,+ }+ } else {+ emoji_presentation_for_code_point(code_point, next_code_point)+ };+ // OPTIMIZATION: Below U+0300, only '#', '*', the ASCII digits, U+00A9 and U+00AE have the Emoji property.+ let has_emoji_property = if code_point < 0x300 {+ matches!(code_point, 0x23 | 0x2a | 0x30..=0x39 | 0xa9 | 0xae)+ } else {+ // SAFETY: Pure Unicode table lookup.+ unsafe { unicode_layout_code_point_has_emoji_property(code_point) }+ };+ debug_assert!(+ code_point >= 0x300 || {+ let presentation = emoji_presentation_for_code_point(code_point, next_code_point);+ // SAFETY: Pure Unicode table lookup.+ let has_property = unsafe { unicode_layout_code_point_has_emoji_property(code_point) };+ presentation.is_emoji == default_presentation.is_emoji+ && presentation.forced == default_presentation.forced+ && has_property == has_emoji_property+ }+ );+ if default_presentation.forced || !has_emoji_property {return default_presentation;}