diff options
| author | bors <bors@rust-lang.org> | 2020-05-22 15:33:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-05-22 15:33:32 +0000 |
| commit | 215f2d3294b08dbdcf8f7d40de21ef1e7eae0a2d (patch) | |
| tree | 7e00d93c42f269f074a0570ad48cc48ad98cf161 /src/libstd | |
| parent | a9ca1ec9280ca1e5020edd699917c3367a30a798 (diff) | |
| parent | e7503ca7bf78eece210c061f324ecfc8e3955321 (diff) | |
| download | rust-215f2d3294b08dbdcf8f7d40de21ef1e7eae0a2d.tar.gz rust-215f2d3294b08dbdcf8f7d40de21ef1e7eae0a2d.zip | |
Auto merge of #72464 - RalfJung:rollup-xhm7w7u, r=RalfJung
Rollup of 7 pull requests Successful merges: - #71829 (Fix suggestion to borrow in struct) - #72123 (Stabilize process_set_argv0 feature for Unix) - #72235 (Clean up E0590 explanation) - #72345 (Clean up E0593 explanation) - #72376 ([self-profling] Record the cgu name when doing codegen for a module) - #72399 (Add fast-path optimization for Ipv4Addr::fmt) - #72435 (rustllvm: Fix warnings about unused function parameters) Failed merges: r? @ghost
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/net/ip.rs | 25 | ||||
| -rw-r--r-- | src/libstd/sys/unix/ext/process.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/vxworks/ext/process.rs | 2 |
3 files changed, 18 insertions, 11 deletions
diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index edc28033c9b..6e2478b8308 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -856,16 +856,23 @@ impl From<Ipv6Addr> for IpAddr { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Display for Ipv4Addr { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - const IPV4_BUF_LEN: usize = 15; // Long enough for the longest possible IPv4 address - let mut buf = [0u8; IPV4_BUF_LEN]; - let mut buf_slice = &mut buf[..]; let octets = self.octets(); - // Note: The call to write should never fail, hence the unwrap - write!(buf_slice, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]).unwrap(); - let len = IPV4_BUF_LEN - buf_slice.len(); - // This unsafe is OK because we know what is being written to the buffer - let buf = unsafe { crate::str::from_utf8_unchecked(&buf[..len]) }; - fmt.pad(buf) + // Fast Path: if there's no alignment stuff, write directly to the buffer + if fmt.precision().is_none() && fmt.width().is_none() { + write!(fmt, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]) + } else { + const IPV4_BUF_LEN: usize = 15; // Long enough for the longest possible IPv4 address + let mut buf = [0u8; IPV4_BUF_LEN]; + let mut buf_slice = &mut buf[..]; + + // Note: The call to write should never fail, hence the unwrap + write!(buf_slice, "{}.{}.{}.{}", octets[0], octets[1], octets[2], octets[3]).unwrap(); + let len = IPV4_BUF_LEN - buf_slice.len(); + + // This unsafe is OK because we know what is being written to the buffer + let buf = unsafe { crate::str::from_utf8_unchecked(&buf[..len]) }; + fmt.pad(buf) + } } } diff --git a/src/libstd/sys/unix/ext/process.rs b/src/libstd/sys/unix/ext/process.rs index fa8670b4aec..048ce24d6ba 100644 --- a/src/libstd/sys/unix/ext/process.rs +++ b/src/libstd/sys/unix/ext/process.rs @@ -111,7 +111,7 @@ pub trait CommandExt { /// /// Set the first process argument, `argv[0]`, to something other than the /// default executable path. - #[unstable(feature = "process_set_argv0", issue = "66510")] + #[stable(feature = "process_set_argv0", since = "1.45.0")] fn arg0<S>(&mut self, arg: S) -> &mut process::Command where S: AsRef<OsStr>; diff --git a/src/libstd/sys/vxworks/ext/process.rs b/src/libstd/sys/vxworks/ext/process.rs index 31e691dd136..c3710f4b912 100644 --- a/src/libstd/sys/vxworks/ext/process.rs +++ b/src/libstd/sys/vxworks/ext/process.rs @@ -111,7 +111,7 @@ pub trait CommandExt { /// /// Set the first process argument, `argv[0]`, to something other than the /// default executable path. - #[unstable(feature = "process_set_argv0", issue = "66510")] + #[stable(feature = "process_set_argv0", since = "1.45.0")] fn arg0<S>(&mut self, arg: S) -> &mut process::Command where S: AsRef<OsStr>; |
