From 1347df898eeb7a0711b5466c5f5c299f463f45e9 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 22 Nov 2024 16:48:44 -0600 Subject: [PATCH] Add ascii fast path for `fish_wcswidth(&wstrw)` chars.all(|c| c.is_ascii()) is autovectorizable but this outperforms even when it's not vectorized. --- src/fallback.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/fallback.rs b/src/fallback.rs index 95cdea0be..3e1334479 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -89,6 +89,11 @@ pub fn fish_wcwidth(c: char) -> isize { /// fish's internal versions of wcwidth and wcswidth, which can use an internal implementation if /// the system one is busted. pub fn fish_wcswidth(s: &wstr) -> isize { + // ascii fast path; empty iterator returns true for .all() + if s.chars().all(|c| c.is_ascii() && !c.is_ascii_control()) { + return s.len() as isize; + } + let mut result = 0; for c in s.chars() { let w = fish_wcwidth(c);