@@ -74,10 +74,13 @@ pub struct Ipv4Addr { |
|
|
74 |
74 |
octets: [u8; 4], |
75 |
75 |
} |
76 |
76 |
|
|
77 |
+#[stable(feature = "rust1", since = "1.0.0")] |
77 |
78 |
impl Hash for Ipv4Addr { |
78 |
79 |
fn hash<H: Hasher>(&self, state: &mut H) { |
79 |
80 |
// 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. |
81 |
84 |
u32::from_le_bytes(self.octets).hash(state); |
82 |
85 |
} |
83 |
86 |
} |
@@ -164,10 +167,13 @@ pub struct Ipv6Addr { |
|
|
164 |
167 |
octets: [u8; 16], |
165 |
168 |
} |
166 |
169 |
|
|
170 |
+#[stable(feature = "rust1", since = "1.0.0")] |
167 |
171 |
impl Hash for Ipv6Addr { |
168 |
172 |
fn hash<H: Hasher>(&self, state: &mut H) { |
169 |
173 |
// 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. |
171 |
177 |
u128::from_le_bytes(self.octets).hash(state); |
172 |
178 |
} |
173 |
179 |
} |