Skip to content

Commit 87f5a98

Browse files
authored
Use to_ne_bytes for converting IPv4Address to octets
It is easier and it should be also faster, because `to_ne_bytes` just calls `mem::transmute`.
1 parent 527b8d4 commit 87f5a98

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
@@ -393,8 +393,7 @@ impl Ipv4Addr {
393393
/// ```
394394
#[stable(feature = "rust1", since = "1.0.0")]
395395
pub fn octets(&self) -> [u8; 4] {
396-
let bits = u32::from_be(self.inner.s_addr);
397-
[(bits >> 24) as u8, (bits >> 16) as u8, (bits >> 8) as u8, bits as u8]
396+
self.inner.s_addr.to_ne_bytes()
398397
}
399398

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

0 commit comments

Comments
 (0)