diff options
| author | Orson Peters <orsonpeters@gmail.com> | 2024-08-11 14:55:29 +0200 |
|---|---|---|
| committer | Orson Peters <orsonpeters@gmail.com> | 2024-08-11 14:55:29 +0200 |
| commit | fce1decc3c6508aa72f590d024e583dd5c0cf04d (patch) | |
| tree | 34a61a22fdf252f831c0f81d04d5a73cf9cad04c | |
| parent | a04a1e464f6c83e1472d3b20141fabd631a5c178 (diff) | |
| download | rust-fce1decc3c6508aa72f590d024e583dd5c0cf04d.tar.gz rust-fce1decc3c6508aa72f590d024e583dd5c0cf04d.zip | |
Do not use unnecessary endian conversion.
| -rw-r--r-- | library/core/src/net/ip_addr.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index 495e9ade383..919f681f911 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -79,9 +79,8 @@ impl Hash for Ipv4Addr { fn hash<H: Hasher>(&self, state: &mut H) { // Hashers are often more efficient at hashing a fixed-width integer // than a bytestring, so convert before hashing. We don't use to_bits() - // here as that involves a byteswap on little-endian machines, which are - // more common than big-endian machines. - u32::from_le_bytes(self.octets).hash(state); + // here as that may involve a byteswap which is unnecessary. + u32::from_ne_bytes(self.octets).hash(state); } } @@ -172,9 +171,8 @@ impl Hash for Ipv6Addr { fn hash<H: Hasher>(&self, state: &mut H) { // Hashers are often more efficient at hashing a fixed-width integer // than a bytestring, so convert before hashing. We don't use to_bits() - // here as that involves byteswaps on little-endian machines, which are - // more common than big-endian machines. - u128::from_le_bytes(self.octets).hash(state); + // here as that may involve unnecessary byteswaps. + u128::from_ne_bytes(self.octets).hash(state); } } |
