diff options
author | Ms2ger <Ms2ger@gmail.com> | 2016-11-23 14:34:39 +0100 |
---|---|---|
committer | Ms2ger <Ms2ger@gmail.com> | 2016-11-23 14:34:39 +0100 |
commit | 9f659e157ad8f069e1685e55b3fd08a890d6e9a3 (patch) | |
tree | 8c3f1b3f6e3cb13e2f7cba90dd37152a0eddafdd /components/net_traits | |
parent | 5946f756d788a5ce9c8f6447b4fa04d57daf9076 (diff) | |
download | servo-9f659e157ad8f069e1685e55b3fd08a890d6e9a3.tar.gz servo-9f659e157ad8f069e1685e55b3fd08a890d6e9a3.zip |
Improve parse_hostsfile.
Diffstat (limited to 'components/net_traits')
-rw-r--r-- | components/net_traits/hosts.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/components/net_traits/hosts.rs b/components/net_traits/hosts.rs index 0a42be55572..5dd947f7c0b 100644 --- a/components/net_traits/hosts.rs +++ b/components/net_traits/hosts.rs @@ -37,10 +37,10 @@ fn create_host_table() -> Option<HashMap<String, IpAddr>> { pub fn parse_hostsfile(hostsfile_content: &str) -> HashMap<String, IpAddr> { let mut host_table = HashMap::new(); for line in hostsfile_content.split('\n') { - let ip_host: Vec<&str> = line.trim().split(|c: char| c == ' ' || c == '\t').collect(); - if ip_host.len() > 1 { - if let Ok(address) = ip_host[0].parse::<IpAddr>() { - for token in ip_host.iter().skip(1) { + let mut ip_host = line.trim().split(|c: char| c == ' ' || c == '\t'); + if let Some(ip) = ip_host.next() { + if let Ok(address) = ip.parse::<IpAddr>() { + for token in ip_host { if token.as_bytes()[0] == b'#' { break; } |