1 // Copyright 2014-2017 The html5ever Project Developers. See the
2 // COPYRIGHT file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 // Run a single benchmark once. For use with profiling tools.
11
12 extern crate html5ever;
13
14 use std::default::Default;
15 use std::io;
16
17 use html5ever::tendril::*;
18 use html5ever::tokenizer::{BufferQueue, Token, TokenSink, TokenSinkResult, Tokenizer};
19
20 struct Sink(Vec<Token>);
21
22 impl TokenSink for Sink {
23 type Handle = ();
24
process_token(&mut self, token: Token, _line_number: u64) -> TokenSinkResult<()>25 fn process_token(&mut self, token: Token, _line_number: u64) -> TokenSinkResult<()> {
26 // Don't use the token, but make sure we don't get
27 // optimized out entirely.
28 self.0.push(token);
29 TokenSinkResult::Continue
30 }
31 }
32
main()33 fn main() {
34 let mut chunk = ByteTendril::new();
35 io::stdin().read_to_tendril(&mut chunk).unwrap();
36 let mut input = BufferQueue::new();
37 input.push_back(chunk.try_reinterpret().unwrap());
38
39 let mut tok = Tokenizer::new(Sink(Vec::new()), Default::default());
40 let _ = tok.feed(&mut input);
41 assert!(input.is_empty());
42 tok.end();
43 }
44