Skip to content

Commit d9f9780

Browse files
Rollup merge of rust-lang#57740 - JakubOnderka:ipv4addr-to_ne_bytes, 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`.
2 parents e917f8b + 87f5a98 commit d9f9780

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/libstd/net/ip.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ impl Ipv4Addr {
392392
/// ```
393393
#[stable(feature = "rust1", since = "1.0.0")]
394394
pub fn octets(&self) -> [u8; 4] {
395-
let bits = u32::from_be(self.inner.s_addr);
396-
[(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8]
395+
self.inner.s_addr.to_ne_bytes()
397396
}
398397

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

0 commit comments

Comments
 (0)