forked from untitaker/html5gum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite entire crate to run on bytes (untitaker#25)
- Loading branch information
Showing
23 changed files
with
1,293 additions
and
960 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use html5gum::Tokenizer; | ||
|
||
fn data_state(c: &mut Criterion) { | ||
for i in [100, 1000, 10000, 1000000] { | ||
let s: String = (0..i).map(|_| 'a').collect(); | ||
c.bench_with_input(BenchmarkId::new("aaa", i), &s, |b, s| { | ||
b.iter(|| for _ in Tokenizer::new(s).infallible() {}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, data_state); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
//! Let's you easily try out the tokenizer with e.g. | ||
//! printf '<h1>Hello world!</h1>' | cargo run --example=tokenize | ||
use html5gum::{BufReadReader, Tokenizer}; | ||
use html5gum::{IoReader, Tokenizer}; | ||
|
||
fn main() { | ||
for token in Tokenizer::new(BufReadReader::new(std::io::stdin().lock())).flatten() { | ||
for token in Tokenizer::new(IoReader::new(std::io::stdin().lock())).flatten() { | ||
println!("{:?}", token); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// This is basically like the arrayvec crate, except crappier, only the subset I need and | ||
/// therefore without unsafe Rust. | ||
pub struct ArrayVec<T: Copy, const CAP: usize> { | ||
content: [T; CAP], | ||
len: usize, | ||
} | ||
|
||
impl<T: Copy, const CAP: usize> ArrayVec<T, CAP> { | ||
pub fn new(filler_item: T) -> Self { | ||
// filler_item is there to avoid usage of MaybeUninit, and can literally be anything at | ||
// all. | ||
ArrayVec { | ||
content: [filler_item; CAP], | ||
len: 0, | ||
} | ||
} | ||
|
||
pub fn push(&mut self, item: T) { | ||
self.content[self.len] = item; | ||
self.len += 1; | ||
} | ||
|
||
pub fn drain(&mut self) -> &[T] { | ||
let rv = &self.content[..self.len]; | ||
self.len = 0; | ||
rv | ||
} | ||
} |
Oops, something went wrong.