mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 22:14:53 +00:00
Remove useless osttr->cstr->osstr roundtrip
This commit is contained in:
parent
980ef6f2f1
commit
8612d34996
2 changed files with 5 additions and 23 deletions
|
@ -441,21 +441,6 @@ fn fish_parse_opt(args: &mut [WString], opts: &mut FishCmdOpts) -> ControlFlow<i
|
||||||
ControlFlow::Continue(optind)
|
ControlFlow::Continue(optind)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cstr_from_osstr(s: &OsStr) -> CString {
|
|
||||||
// is there no better way to do this?
|
|
||||||
// this is
|
|
||||||
// CStr::from_bytes_until_nul(s.as_bytes()).unwrap()
|
|
||||||
// except we need to add the nul if it is not present
|
|
||||||
CString::new(
|
|
||||||
s.as_bytes()
|
|
||||||
.iter()
|
|
||||||
.cloned()
|
|
||||||
.take_while(|&c| c != b'\0')
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
PROGRAM_NAME.set(L!("fish")).unwrap();
|
PROGRAM_NAME.set(L!("fish")).unwrap();
|
||||||
if !cfg!(small_main_stack) {
|
if !cfg!(small_main_stack) {
|
||||||
|
@ -617,8 +602,7 @@ fn throwing_main() -> i32 {
|
||||||
|
|
||||||
// TODO: if-let-chains
|
// TODO: if-let-chains
|
||||||
if opts.profile_startup_output.is_some() && opts.profile_startup_output != opts.profile_output {
|
if opts.profile_startup_output.is_some() && opts.profile_startup_output != opts.profile_output {
|
||||||
let s = cstr_from_osstr(&opts.profile_startup_output.unwrap());
|
parser.emit_profiling(&opts.profile_startup_output.unwrap());
|
||||||
parser.emit_profiling(s.as_bytes());
|
|
||||||
|
|
||||||
// If we are profiling both, ensure the startup data only
|
// If we are profiling both, ensure the startup data only
|
||||||
// ends up in the startup file.
|
// ends up in the startup file.
|
||||||
|
@ -720,8 +704,7 @@ fn throwing_main() -> i32 {
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(profile_output) = opts.profile_output {
|
if let Some(profile_output) = opts.profile_output {
|
||||||
let s = cstr_from_osstr(&profile_output);
|
parser.emit_profiling(&profile_output);
|
||||||
parser.emit_profiling(s.as_bytes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
history::save_all();
|
history::save_all();
|
||||||
|
|
|
@ -39,7 +39,6 @@ use std::cell::{Ref, RefCell, RefMut};
|
||||||
use std::ffi::{CStr, OsStr};
|
use std::ffi::{CStr, OsStr};
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
use std::os::fd::{AsRawFd, OwnedFd, RawFd};
|
use std::os::fd::{AsRawFd, OwnedFd, RawFd};
|
||||||
use std::os::unix::prelude::OsStrExt;
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
#[cfg(target_has_atomic = "64")]
|
#[cfg(target_has_atomic = "64")]
|
||||||
use std::sync::atomic::AtomicU64;
|
use std::sync::atomic::AtomicU64;
|
||||||
|
@ -976,17 +975,17 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Output profiling data to the given filename.
|
/// Output profiling data to the given filename.
|
||||||
pub fn emit_profiling(&self, path: &[u8]) {
|
pub fn emit_profiling(&self, path: &OsStr) {
|
||||||
// Save profiling information. OK to not use CLO_EXEC here because this is called while fish is
|
// Save profiling information. OK to not use CLO_EXEC here because this is called while fish is
|
||||||
// exiting (and hence will not fork).
|
// exiting (and hence will not fork).
|
||||||
let f = match std::fs::File::create(OsStr::from_bytes(path)) {
|
let f = match std::fs::File::create(path) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
FLOG!(
|
FLOG!(
|
||||||
warning,
|
warning,
|
||||||
wgettext_fmt!(
|
wgettext_fmt!(
|
||||||
"Could not write profiling information to file '%s': %s",
|
"Could not write profiling information to file '%s': %s",
|
||||||
&String::from_utf8_lossy(path),
|
path.to_string_lossy(),
|
||||||
err.to_string()
|
err.to_string()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue