about summary refs log tree commit diff
path: root/src/libstd/sys/vxworks
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-07-23 00:42:12 -0700
committerGitHub <noreply@github.com>2020-07-23 00:42:12 -0700
commitbea2eedcb5cb08c08069db554abe7880a3dfd693 (patch)
tree6e56d61ce1637860042bed4fc8a078bd84253cde /src/libstd/sys/vxworks
parent5629223782074cc38597775e47e947081253ac26 (diff)
parent0de7fade1053f553f83ac603079602d50ab14e19 (diff)
downloadrust-bea2eedcb5cb08c08069db554abe7880a3dfd693.tar.gz
rust-bea2eedcb5cb08c08069db554abe7880a3dfd693.zip
Rollup merge of #74587 - lzutao:consts, r=dtolnay
Prefer constant over function

Just that I prefer constants over functions that can be made const.
Diffstat (limited to 'src/libstd/sys/vxworks')
-rw-r--r--src/libstd/sys/vxworks/fd.rs18
-rw-r--r--src/libstd/sys/vxworks/time.rs2
2 files changed, 9 insertions, 11 deletions
diff --git a/src/libstd/sys/vxworks/fd.rs b/src/libstd/sys/vxworks/fd.rs
index 7384cbae3a1..ea186846929 100644
--- a/src/libstd/sys/vxworks/fd.rs
+++ b/src/libstd/sys/vxworks/fd.rs
@@ -13,12 +13,10 @@ pub struct FileDesc {
     fd: c_int,
 }
 
-fn max_len() -> usize {
-    // The maximum read limit on most posix-like systems is `SSIZE_MAX`,
-    // with the man page quoting that if the count of bytes to read is
-    // greater than `SSIZE_MAX` the result is "unspecified".
-    <ssize_t>::MAX as usize
-}
+// The maximum read limit on most POSIX-like systems is `SSIZE_MAX`,
+// with the man page quoting that if the count of bytes to read is
+// greater than `SSIZE_MAX` the result is "unspecified".
+const READ_LIMIT: usize = ssize_t::MAX as usize;
 
 impl FileDesc {
     pub fn new(fd: c_int) -> FileDesc {
@@ -38,7 +36,7 @@ impl FileDesc {
 
     pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
         let ret = cvt(unsafe {
-            libc::read(self.fd, buf.as_mut_ptr() as *mut c_void, cmp::min(buf.len(), max_len()))
+            libc::read(self.fd, buf.as_mut_ptr() as *mut c_void, cmp::min(buf.len(), READ_LIMIT))
         })?;
         Ok(ret as usize)
     }
@@ -79,7 +77,7 @@ impl FileDesc {
             cvt_pread(
                 self.fd,
                 buf.as_mut_ptr() as *mut c_void,
-                cmp::min(buf.len(), max_len()),
+                cmp::min(buf.len(), READ_LIMIT),
                 offset as i64,
             )
             .map(|n| n as usize)
@@ -88,7 +86,7 @@ impl FileDesc {
 
     pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
         let ret = cvt(unsafe {
-            libc::write(self.fd, buf.as_ptr() as *const c_void, cmp::min(buf.len(), max_len()))
+            libc::write(self.fd, buf.as_ptr() as *const c_void, cmp::min(buf.len(), READ_LIMIT))
         })?;
         Ok(ret as usize)
     }
@@ -124,7 +122,7 @@ impl FileDesc {
             cvt_pwrite(
                 self.fd,
                 buf.as_ptr() as *const c_void,
-                cmp::min(buf.len(), max_len()),
+                cmp::min(buf.len(), READ_LIMIT),
                 offset as i64,
             )
             .map(|n| n as usize)
diff --git a/src/libstd/sys/vxworks/time.rs b/src/libstd/sys/vxworks/time.rs
index 8365c9ee9c9..8f46f4d284f 100644
--- a/src/libstd/sys/vxworks/time.rs
+++ b/src/libstd/sys/vxworks/time.rs
@@ -1,6 +1,6 @@
 use crate::cmp::Ordering;
 use crate::time::Duration;
-use ::core::hash::{Hash, Hasher};
+use core::hash::{Hash, Hasher};
 
 pub use self::inner::{Instant, SystemTime, UNIX_EPOCH};
 use crate::convert::TryInto;