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.
This commit is contained in:
Mahmoud Al-Qudsi 2024-11-22 16:48:44 -06:00
parent 2fd51355c3
commit 1347df898e

View File

@ -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 /// fish's internal versions of wcwidth and wcswidth, which can use an internal implementation if
/// the system one is busted. /// the system one is busted.
pub fn fish_wcswidth(s: &wstr) -> isize { 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; let mut result = 0;
for c in s.chars() { for c in s.chars() {
let w = fish_wcwidth(c); let w = fish_wcwidth(c);