mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-19 05:13:44 +08:00
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:
parent
2fd51355c3
commit
1347df898e
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user