Skip to content

Commit

Permalink
Merge pull request #362 from Keruspe/drop-chain-4
Browse files Browse the repository at this point in the history
Port benches to do_parse
  • Loading branch information
Geal committed Dec 10, 2016
2 parents 25950ce + c4ed6c6 commit c7d76f9
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions benches/http.rs
Expand Up @@ -65,53 +65,53 @@ fn is_version(c: u8) -> bool {
named!(line_ending, alt!(tag!("\r\n") | tag!("\n")));

fn request_line<'a>(input: &'a [u8]) -> IResult<&'a[u8], Request<'a>> {
chain!(input,
method: take_while1!(is_token) ~
take_while1!(is_space) ~
url: take_while1!(is_not_space) ~
take_while1!(is_space) ~
version: http_version ~
line_ending,

|| Request {
do_parse!(input,
method: take_while1!(is_token) >>
take_while1!(is_space) >>
url: take_while1!(is_not_space) >>
take_while1!(is_space) >>
version: http_version >>
line_ending >>

(Request {
method: method,
uri: url,
version: version,
})
}))
}

named!(http_version, chain!(
tag!("HTTP/") ~
version: take_while1!(is_version),

|| version));
named!(http_version, do_parse!(
tag!("HTTP/") >>
version: take_while1!(is_version) >>

named!(message_header_value, chain!(
take_while1!(is_horizontal_space) ~
data: take_while1!(not_line_ending) ~
line_ending,

|| data));
(version)));

named!(message_header_value, do_parse!(
take_while1!(is_horizontal_space) >>
data: take_while1!(not_line_ending) >>
line_ending >>

(data)));

fn message_header<'a>(input: &'a [u8]) -> IResult<&'a[u8], Header<'a>> {
chain!(input,
name: take_while1!(is_token) ~
char!(':') ~
values: many1!(message_header_value),
do_parse!(input,
name: take_while1!(is_token) >>
char!(':') >>
values: many1!(message_header_value) >>

|| Header {
(Header {
name: name,
value: values,
})
}))
}

fn request<'a>(input: &'a [u8]) -> IResult<&'a[u8], (Request<'a>, Vec<Header<'a>>)> {
chain!(input,
req: request_line ~
h: many1!(message_header) ~
line_ending,
do_parse!(input,
req: request_line >>
h: many1!(message_header) >>
line_ending >>

|| (req, h))
(req, h))
}


Expand All @@ -130,7 +130,7 @@ fn parse(data:&[u8]) -> Option<Vec<(Request, Vec<Header>)>> {
break;
}
},
IResult::Error(e) => return None/*panic!("{:?}", e)*/,
IResult::Error(_) => return None/*panic!("{:?}", e)*/,
IResult::Incomplete(_) => return None/*panic!("Incomplete!")*/,
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ fn main() {
let _ = file.read_to_end(&mut contents).unwrap();
}

let mut buf = &contents[..];
let buf = &contents[..];
loop { parse(buf); }
}

0 comments on commit c7d76f9

Please sign in to comment.