mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00: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
1 changed files with 5 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue