1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

uucore::fsext: Avoid unnecessary allocations

This commit is contained in:
Jan Verbeek 2021-08-27 15:09:42 +02:00
parent 9d5133157a
commit 8cfe0290cd

View file

@ -26,7 +26,7 @@ const MAX_PATH: usize = 266;
static EXIT_ERR: i32 = 1; static EXIT_ERR: i32 = 1;
#[cfg(windows)] #[cfg(windows)]
use std::ffi::OsString; use std::ffi::OsStr;
#[cfg(windows)] #[cfg(windows)]
use std::os::windows::ffi::OsStrExt; use std::os::windows::ffi::OsStrExt;
#[cfg(windows)] #[cfg(windows)]
@ -43,11 +43,12 @@ use winapi::um::handleapi::INVALID_HANDLE_VALUE;
#[cfg(windows)] #[cfg(windows)]
use winapi::um::winbase::DRIVE_REMOTE; use winapi::um::winbase::DRIVE_REMOTE;
// Warning: the pointer has to be used *immediately* or the Vec
// it points to will be dropped!
#[cfg(windows)] #[cfg(windows)]
macro_rules! String2LPWSTR { macro_rules! String2LPWSTR {
($str: expr) => { ($str: expr) => {
OsString::from($str.clone()) OsStr::new(&$str)
.as_os_str()
.encode_wide() .encode_wide()
.chain(Some(0)) .chain(Some(0))
.collect::<Vec<u16>>() .collect::<Vec<u16>>()
@ -238,8 +239,7 @@ impl MountInfo {
volume_name.pop(); volume_name.pop();
unsafe { unsafe {
QueryDosDeviceW( QueryDosDeviceW(
OsString::from(volume_name.clone()) OsStr::new(&volume_name)
.as_os_str()
.encode_wide() .encode_wide()
.chain(Some(0)) .chain(Some(0))
.skip(4) .skip(4)