Skip to content

Commit

Permalink
Convert a simple tail call to a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Jun 29, 2016
1 parent d6237ce commit a03a82e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/libstd/sys/common/net.rs
Expand Up @@ -121,16 +121,20 @@ pub struct LookupHost {
impl Iterator for LookupHost {
type Item = SocketAddr;
fn next(&mut self) -> Option<SocketAddr> {
let result;
unsafe {
if self.cur.is_null() { return None }
result = sockaddr_to_addr(mem::transmute((*self.cur).ai_addr),
(*self.cur).ai_addrlen as usize).ok();
self.cur = (*self.cur).ai_next as *mut c::addrinfo;
}
match result {
Some(r) => Some(r),
None => self.next(),
loop {
unsafe {
let cur = match self.cur.as_ref() {
None => return None,
Some(c) => c,
};
self.cur = cur.ai_next;
match sockaddr_to_addr(mem::transmute(cur.ai_addr),
cur.ai_addrlen as usize)
{
Ok(addr) => return Some(addr),
Err(_) => continue,
}
}
}
}
}
Expand Down

0 comments on commit a03a82e

Please sign in to comment.