From cdf730ca3cdc5ce7dfb284986d39398ac23187b2 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Wed, 28 Nov 2018 10:47:12 -0700 Subject: Prefer `map(drop)` to `map(|_| ())` I previously advocated for the latter syntax on stylistic grounds. But it generates less efficient code, because it creates a new lambda function for each usage. The optimizer does not combine them. This change saves about 6KB of code. --- src/sys/stat.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/sys/stat.rs') diff --git a/src/sys/stat.rs b/src/sys/stat.rs index 925c0ede..f3a2e7e3 100644 --- a/src/sys/stat.rs +++ b/src/sys/stat.rs @@ -131,7 +131,7 @@ pub fn fstatat(dirfd: RawFd, pathname: &P, f: AtFlags) -> R pub fn fchmod(fd: RawFd, mode: Mode) -> Result<()> { let res = unsafe { libc::fchmod(fd, mode.bits() as mode_t) }; - Errno::result(res).map(|_| ()) + Errno::result(res).map(drop) } /// Flags for `fchmodat` function. @@ -177,7 +177,7 @@ pub fn fchmodat( ) })?; - Errno::result(res).map(|_| ()) + Errno::result(res).map(drop) } /// Change the access and modification times of a file. @@ -196,7 +196,7 @@ pub fn utimes(path: &P, atime: &TimeVal, mtime: &TimeVal) - libc::utimes(cstr.as_ptr(), ×[0]) })?; - Errno::result(res).map(|_| ()) + Errno::result(res).map(drop) } /// Change the access and modification times of a file without following symlinks. @@ -216,7 +216,7 @@ pub fn lutimes(path: &P, atime: &TimeVal, mtime: &TimeVal) libc::lutimes(cstr.as_ptr(), ×[0]) })?; - Errno::result(res).map(|_| ()) + Errno::result(res).map(drop) } /// Change the access and modification times of the file specified by a file descriptor. @@ -229,7 +229,7 @@ pub fn futimens(fd: RawFd, atime: &TimeSpec, mtime: &TimeSpec) -> Result<()> { let times: [libc::timespec; 2] = [*atime.as_ref(), *mtime.as_ref()]; let res = unsafe { libc::futimens(fd, ×[0]) }; - Errno::result(res).map(|_| ()) + Errno::result(res).map(drop) } /// Flags for `utimensat` function. @@ -277,5 +277,5 @@ pub fn utimensat( ) })?; - Errno::result(res).map(|_| ()) + Errno::result(res).map(drop) } -- cgit v1.2.3