Reject too-long IPs quicker
Now that there can't be a bunch of leading zeros, parsing can be optimized a bit.
This commit is contained in:
parent
69de693af9
commit
b9b97bbb9d
1 changed files with 6 additions and 1 deletions
|
|
@ -289,7 +289,12 @@ impl FromStr for IpAddr {
|
|||
impl FromStr for Ipv4Addr {
|
||||
type Err = AddrParseError;
|
||||
fn from_str(s: &str) -> Result<Ipv4Addr, AddrParseError> {
|
||||
Parser::new(s).parse_with(|p| p.read_ipv4_addr())
|
||||
// don't try to parse if too long
|
||||
if s.len() > 15 {
|
||||
Err(AddrParseError(()))
|
||||
} else {
|
||||
Parser::new(s).parse_with(|p| p.read_ipv4_addr())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue