Skip to content

Commit 0741565

Browse files
committed
df: get rid of clone calls
1 parent 5aade31 commit 0741565

3 files changed

Lines changed: 14 additions & 18 deletions

File tree

src/uu/df/src/df.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,19 +335,18 @@ fn get_all_filesystems(opt: &Options) -> UResult<Vec<Filesystem>> {
335335
// both the mount information and usage information.
336336
#[cfg(not(windows))]
337337
{
338-
let maybe_mount = |m| Filesystem::from_mount(&mounts, &m, None).ok();
338+
let maybe_mount = |m| Filesystem::from_mount(&mounts, m, None).ok();
339339
Ok(mounts
340-
.clone()
341-
.into_iter()
340+
.iter()
342341
.filter_map(maybe_mount)
343342
.filter(|fs| opt.show_all_fs || fs.usage.blocks > 0)
344343
.collect())
345344
}
346345
#[cfg(windows)]
347346
{
348-
let maybe_mount = |m| Filesystem::from_mount(&m, None).ok();
347+
let maybe_mount = |m| Filesystem::from_mount(m, None).ok();
349348
Ok(mounts
350-
.into_iter()
349+
.iter()
351350
.filter_map(maybe_mount)
352351
.filter(|fs| opt.show_all_fs || fs.usage.blocks > 0)
353352
.collect())

src/uu/df/src/filesystem.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ where
134134
// make code more testable
135135
.map(|m| (m, std::fs::canonicalize(&m.dev_name)))
136136
// Ignore non existing paths
137-
.filter(|m| m.1.is_ok())
138-
.map(|m| (m.0, m.1.ok().unwrap()))
137+
.filter_map(|m| m.1.ok().map(|m1| (m.0, m1)))
139138
// Try to find canonicalized device name corresponding to entered path
140139
.find(|m| m.1.eq(&path))
141140
.map(|m| m.0);
@@ -156,20 +155,20 @@ impl Filesystem {
156155
let stat_path = if mount_info.mount_dir.is_empty() {
157156
#[cfg(unix)]
158157
{
159-
mount_info.dev_name.clone().into()
158+
mount_info.dev_name.as_ref()
160159
}
161160
#[cfg(windows)]
162161
{
163162
// On windows, we expect the volume id
164-
mount_info.dev_id.clone().into()
163+
mount_info.dev_id.as_ref()
165164
}
166165
} else {
167-
mount_info.mount_dir.clone()
166+
mount_info.mount_dir.as_os_str()
168167
};
169168
#[cfg(unix)]
170-
let usage = FsUsage::new(statfs(&stat_path).ok()?);
169+
let usage = FsUsage::new(statfs(stat_path).ok()?);
171170
#[cfg(windows)]
172-
let usage = FsUsage::new(Path::new(&stat_path)).ok()?;
171+
let usage = FsUsage::new(Path::new(stat_path)).ok()?;
173172
Some(Self {
174173
file,
175174
mount_info,
@@ -234,12 +233,10 @@ impl Filesystem {
234233
where
235234
P: AsRef<Path>,
236235
{
237-
let file = path.as_ref().as_os_str().to_owned();
236+
let path = path.as_ref();
237+
let file = path.as_os_str().to_owned();
238238

239-
let canonical_path = path
240-
.as_ref()
241-
.canonicalize()
242-
.map_err(|_| FsError::InvalidPath)?;
239+
let canonical_path = path.canonicalize().map_err(|_| FsError::InvalidPath)?;
243240

244241
let stat_result = statfs(canonical_path.as_os_str()).map_err(|_| FsError::MountMissing)?;
245242
let mount_dir = find_mount_point(&canonical_path).map_err(|_| FsError::MountMissing)?;

src/uu/df/src/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ mod tests {
11231123
..Default::default()
11241124
};
11251125

1126-
let table = Table::new(&options, filesystems.clone());
1126+
let table = Table::new(&options, filesystems);
11271127
let mut data: Vec<u8> = vec![];
11281128
table.write_to(&mut data).expect("Write error.");
11291129
assert_eq!(

0 commit comments

Comments
 (0)