Skip to content

Commit

Permalink
Rollup merge of rust-lang#57740 - JakubOnderka:ipv4addr-to_ne_bytes, …
Browse files Browse the repository at this point in the history
…r=scottmcm

Use `to_ne_bytes` for converting IPv4Addr to octets

It is easier and it should be also faster, because [`to_ne_bytes`](https://doc.rust-lang.org/std/primitive.u32.html#method.to_ne_bytes) just calls `mem::transmute`.
  • Loading branch information
pietroalbini authored Feb 10, 2019
2 parents 509d592 + 87f5a98 commit 26947dd
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/libstd/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ impl Ipv4Addr {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn octets(&self) -> [u8; 4] {
let bits = u32::from_be(self.inner.s_addr);
[(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8]
self.inner.s_addr.to_ne_bytes()
}

/// Returns [`true`] for the special 'unspecified' address (0.0.0.0).
Expand Down

0 comments on commit 26947dd

Please sign in to comment.