unix/vxworks: make DirEntry slightly smaller
`DirEntry` contains a `ReadDir` handle, which used to just be a wrapper
on `Arc<InnerReadDir>`. Commit af75314ecd
added `end_of_stream: bool`
which is not needed by `DirEntry`, but adds 8 bytes after padding. We
can let `DirEntry` have an `Arc<InnerReadDir>` directly to avoid that.
This commit is contained in:
parent
53a4c3b0ba
commit
c1297eca3e
2 changed files with 8 additions and 10 deletions
|
@ -183,7 +183,6 @@ struct InnerReadDir {
|
||||||
root: PathBuf,
|
root: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ReadDir {
|
pub struct ReadDir {
|
||||||
inner: Arc<InnerReadDir>,
|
inner: Arc<InnerReadDir>,
|
||||||
end_of_stream: bool,
|
end_of_stream: bool,
|
||||||
|
@ -196,7 +195,7 @@ unsafe impl Sync for Dir {}
|
||||||
|
|
||||||
pub struct DirEntry {
|
pub struct DirEntry {
|
||||||
entry: dirent64,
|
entry: dirent64,
|
||||||
dir: ReadDir,
|
dir: Arc<InnerReadDir>,
|
||||||
// We need to store an owned copy of the entry name
|
// We need to store an owned copy of the entry name
|
||||||
// on Solaris and Fuchsia because a) it uses a zero-length
|
// on Solaris and Fuchsia because a) it uses a zero-length
|
||||||
// array to store the name, b) its lifetime between readdir
|
// array to store the name, b) its lifetime between readdir
|
||||||
|
@ -443,7 +442,7 @@ impl Iterator for ReadDir {
|
||||||
name: slice::from_raw_parts(name as *const u8, namelen as usize)
|
name: slice::from_raw_parts(name as *const u8, namelen as usize)
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.into_boxed_slice(),
|
.into_boxed_slice(),
|
||||||
dir: self.clone(),
|
dir: Arc::clone(&self.inner),
|
||||||
};
|
};
|
||||||
if ret.name_bytes() != b"." && ret.name_bytes() != b".." {
|
if ret.name_bytes() != b"." && ret.name_bytes() != b".." {
|
||||||
return Some(Ok(ret));
|
return Some(Ok(ret));
|
||||||
|
@ -464,7 +463,7 @@ impl Iterator for ReadDir {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut ret = DirEntry { entry: mem::zeroed(), dir: self.clone() };
|
let mut ret = DirEntry { entry: mem::zeroed(), dir: Arc::clone(&self.inner) };
|
||||||
let mut entry_ptr = ptr::null_mut();
|
let mut entry_ptr = ptr::null_mut();
|
||||||
loop {
|
loop {
|
||||||
if readdir64_r(self.inner.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
|
if readdir64_r(self.inner.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
|
||||||
|
@ -497,7 +496,7 @@ impl Drop for Dir {
|
||||||
|
|
||||||
impl DirEntry {
|
impl DirEntry {
|
||||||
pub fn path(&self) -> PathBuf {
|
pub fn path(&self) -> PathBuf {
|
||||||
self.dir.inner.root.join(OsStr::from_bytes(self.name_bytes()))
|
self.dir.root.join(OsStr::from_bytes(self.name_bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_name(&self) -> OsString {
|
pub fn file_name(&self) -> OsString {
|
||||||
|
@ -506,7 +505,7 @@ impl DirEntry {
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "android"))]
|
||||||
pub fn metadata(&self) -> io::Result<FileAttr> {
|
pub fn metadata(&self) -> io::Result<FileAttr> {
|
||||||
let fd = cvt(unsafe { dirfd(self.dir.inner.dirp.0) })?;
|
let fd = cvt(unsafe { dirfd(self.dir.dirp.0) })?;
|
||||||
let name = self.entry.d_name.as_ptr();
|
let name = self.entry.d_name.as_ptr();
|
||||||
|
|
||||||
cfg_has_statx! {
|
cfg_has_statx! {
|
||||||
|
|
|
@ -27,7 +27,6 @@ struct InnerReadDir {
|
||||||
root: PathBuf,
|
root: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ReadDir {
|
pub struct ReadDir {
|
||||||
inner: Arc<InnerReadDir>,
|
inner: Arc<InnerReadDir>,
|
||||||
end_of_stream: bool,
|
end_of_stream: bool,
|
||||||
|
@ -40,7 +39,7 @@ unsafe impl Sync for Dir {}
|
||||||
|
|
||||||
pub struct DirEntry {
|
pub struct DirEntry {
|
||||||
entry: dirent,
|
entry: dirent,
|
||||||
dir: ReadDir,
|
dir: Arc<InnerReadDir>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -170,7 +169,7 @@ impl Iterator for ReadDir {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut ret = DirEntry { entry: mem::zeroed(), dir: self.clone() };
|
let mut ret = DirEntry { entry: mem::zeroed(), dir: Arc::clone(&self.inner) };
|
||||||
let mut entry_ptr = ptr::null_mut();
|
let mut entry_ptr = ptr::null_mut();
|
||||||
loop {
|
loop {
|
||||||
if readdir64_r(self.inner.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
|
if readdir64_r(self.inner.dirp.0, &mut ret.entry, &mut entry_ptr) != 0 {
|
||||||
|
@ -204,7 +203,7 @@ impl Drop for Dir {
|
||||||
impl DirEntry {
|
impl DirEntry {
|
||||||
pub fn path(&self) -> PathBuf {
|
pub fn path(&self) -> PathBuf {
|
||||||
use crate::sys::vxworks::ext::ffi::OsStrExt;
|
use crate::sys::vxworks::ext::ffi::OsStrExt;
|
||||||
self.dir.inner.root.join(OsStr::from_bytes(self.name_bytes()))
|
self.dir.root.join(OsStr::from_bytes(self.name_bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn file_name(&self) -> OsString {
|
pub fn file_name(&self) -> OsString {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue