diff options
| author | CDirkx <christiaan@dirkx.com> | 2020-09-01 21:05:26 +0200 |
|---|---|---|
| committer | CDirkx <christiaan@dirkx.com> | 2020-09-01 21:05:26 +0200 |
| commit | a43dd4f4014af0f70c032eb23c5cbf4c2829b7c8 (patch) | |
| tree | 1e20718b3926d9984d59be98a1aeb22fc3334037 /library/std/src/net | |
| parent | cd08deff3c9c0de3ecd78883a3df4c9089b715d1 (diff) | |
| download | rust-a43dd4f4014af0f70c032eb23c5cbf4c2829b7c8.tar.gz rust-a43dd4f4014af0f70c032eb23c5cbf4c2829b7c8.zip | |
Change implementation of `Ipv6Addr::is_unspecified` and `is_loopback` from `matches!` to `u128` comparison
Done because `matches!` doesn't optimize well with array comparisons
Diffstat (limited to 'library/std/src/net')
| -rw-r--r-- | library/std/src/net/ip.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index 8e3dbf8fcb4..341a112df71 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -1139,7 +1139,7 @@ impl Ipv6Addr { #[rustc_const_unstable(feature = "const_ipv6", issue = "76205")] #[stable(since = "1.7.0", feature = "ip_17")] pub const fn is_unspecified(&self) -> bool { - matches!(self.segments(), [0, 0, 0, 0, 0, 0, 0, 0]) + u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::UNSPECIFIED.octets()) } /// Returns [`true`] if this is a loopback address (::1). @@ -1160,7 +1160,7 @@ impl Ipv6Addr { #[rustc_const_unstable(feature = "const_ipv6", issue = "76205")] #[stable(since = "1.7.0", feature = "ip_17")] pub const fn is_loopback(&self) -> bool { - matches!(self.segments(), [0, 0, 0, 0, 0, 0, 0, 1]) + u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::LOCALHOST.octets()) } /// Returns [`true`] if the address appears to be globally routable. |
