Skip to content

Commit ec7a585

Browse files
committed
Do not use unnecessary endian conversion.
1 parent 451feca commit ec7a585

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Diff for: core/src/net/ip_addr.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ impl Hash for Ipv4Addr {
7979
fn hash<H: Hasher>(&self, state: &mut H) {
8080
// Hashers are often more efficient at hashing a fixed-width integer
8181
// than a bytestring, so convert before hashing. We don't use to_bits()
82-
// here as that involves a byteswap on little-endian machines, which are
83-
// more common than big-endian machines.
84-
u32::from_le_bytes(self.octets).hash(state);
82+
// here as that may involve a byteswap which is unnecessary.
83+
u32::from_ne_bytes(self.octets).hash(state);
8584
}
8685
}
8786

@@ -172,9 +171,8 @@ impl Hash for Ipv6Addr {
172171
fn hash<H: Hasher>(&self, state: &mut H) {
173172
// Hashers are often more efficient at hashing a fixed-width integer
174173
// than a bytestring, so convert before hashing. We don't use to_bits()
175-
// here as that involves byteswaps on little-endian machines, which are
176-
// more common than big-endian machines.
177-
u128::from_le_bytes(self.octets).hash(state);
174+
// here as that may involve unnecessary byteswaps.
175+
u128::from_ne_bytes(self.octets).hash(state);
178176
}
179177
}
180178

0 commit comments

Comments
 (0)