mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 05:43:11 +00:00
Replace sprintf call with write!
This reduces the time for the Rust tests from a few minutes to ~40 seconds. Also fix some bogus comments which were ported from C++.
This commit is contained in:
parent
b16f617fb3
commit
c48c0bb226
1 changed files with 5 additions and 5 deletions
|
@ -25,6 +25,7 @@ use num_traits::ToPrimitive;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::{CStr, CString, OsString};
|
use std::ffi::{CStr, CString, OsString};
|
||||||
|
use std::fmt::Write;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::os::fd::{AsRawFd, RawFd};
|
use std::os::fd::{AsRawFd, RawFd};
|
||||||
|
@ -343,14 +344,13 @@ fn escape_string_url(input: &wstr) -> WString {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// All other chars need to have their UTF-8 representation encoded in hex.
|
// All other chars need to have their narrow representation encoded in hex.
|
||||||
sprintf!(=> &mut out, "%%%02X"L, byte);
|
write!(out, "%{:02X}", byte).expect("Writes to strings cannot fail");
|
||||||
}
|
}
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Escape a string in a fashion suitable for using as a fish var name. Store the result in out_str.
|
/// Escape a string in a fashion suitable for using as a fish var name. Store the result in out_str.
|
||||||
#[widestrs]
|
|
||||||
fn escape_string_var(input: &wstr) -> WString {
|
fn escape_string_var(input: &wstr) -> WString {
|
||||||
let mut prev_was_hex_encoded = false;
|
let mut prev_was_hex_encoded = false;
|
||||||
let narrow = wcs2string(input);
|
let narrow = wcs2string(input);
|
||||||
|
@ -371,8 +371,8 @@ fn escape_string_var(input: &wstr) -> WString {
|
||||||
out.push_str("__");
|
out.push_str("__");
|
||||||
prev_was_hex_encoded = false;
|
prev_was_hex_encoded = false;
|
||||||
} else {
|
} else {
|
||||||
// All other chars need to have their UTF-8 representation encoded in hex.
|
// All other chars need to have their narrow representation encoded in hex.
|
||||||
sprintf!(=> &mut out, "_%02X"L, c);
|
write!(out, "_{:02X}", c).expect("Writes to strings cannot fail");
|
||||||
prev_was_hex_encoded = true;
|
prev_was_hex_encoded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue