from_str is implemented like so:
|
/// Read an IP Address, either IPv4 or IPv6. |
|
fn read_ip_addr(&mut self) -> Option<IpAddr> { |
|
self.read_ipv4_addr().map(IpAddr::V4).or_else(move || self.read_ipv6_addr().map(IpAddr::V6)) |
|
} |
This unnecessarily penalizes ipv6 addresses, because the parser will always do a full linear scan of the input before it even starts to parse the address. Instead, it could use the knowledge that IPv4 addresses are at most 15 bytes long to skip directly to
read_ipv6_addr for longer strings.
@rustbot label: +I-slow +T-libs +C-enhancement
from_stris implemented like so:rust/library/std/src/net/parser.rs
Lines 226 to 229 in 5f4e067
This unnecessarily penalizes ipv6 addresses, because the parser will always do a full linear scan of the input before it even starts to parse the address. Instead, it could use the knowledge that IPv4 addresses are at most 15 bytes long to skip directly to
read_ipv6_addrfor longer strings.@rustbot label: +I-slow +T-libs +C-enhancement