Skip to content

Commit 451feca

Browse files
committed
Fix stability annotation and expand comment
1 parent 2e34ac3 commit 451feca

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ pub struct Ipv4Addr {
7474
octets: [u8; 4],
7575
}
7676

77+
#[stable(feature = "rust1", since = "1.0.0")]
7778
impl Hash for Ipv4Addr {
7879
fn hash<H: Hasher>(&self, state: &mut H) {
7980
// Hashers are often more efficient at hashing a fixed-width integer
80-
// than a bytestring, so convert before hashing.
81+
// 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.
8184
u32::from_le_bytes(self.octets).hash(state);
8285
}
8386
}
@@ -164,10 +167,13 @@ pub struct Ipv6Addr {
164167
octets: [u8; 16],
165168
}
166169

170+
#[stable(feature = "rust1", since = "1.0.0")]
167171
impl Hash for Ipv6Addr {
168172
fn hash<H: Hasher>(&self, state: &mut H) {
169173
// Hashers are often more efficient at hashing a fixed-width integer
170-
// than a bytestring, so convert before hashing.
174+
// 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.
171177
u128::from_le_bytes(self.octets).hash(state);
172178
}
173179
}

0 commit comments

Comments
 (0)