From 2c57e6e927ed1c9059a0adc10aba4292871a4d09 Mon Sep 17 00:00:00 2001 From: Cong-Cong Pan Date: Tue, 26 May 2026 17:08:05 +0800 Subject: [PATCH] perf: utf16_len by ascii fast path --- src/helpers.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/helpers.rs b/src/helpers.rs index 4e57cd68..dd764570 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -158,6 +158,9 @@ pub fn encode_mappings(mappings: impl Iterator) -> String { /// Formula: `utf16_len = byte_length - continuation_bytes + four_byte_leaders` #[inline] pub fn utf16_len(s: &str) -> usize { + if s.is_ascii() { + return s.len(); + } simd_utf16_len::utf16_len(s) }