Skip to content

Commit 70cbb88

Browse files
committed
Run rustfmt on everything
1 parent 5a2e6c6 commit 70cbb88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2777
-1997
lines changed

html5ever/benches/tokenizer.rs

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
extern crate rustc_test as test;
1110
extern crate html5ever;
11+
extern crate rustc_test as test;
1212

13-
use std::{fs, env, cmp};
14-
use std::path::PathBuf;
1513
use std::default::Default;
14+
use std::path::PathBuf;
15+
use std::{cmp, env, fs};
1616

1717
use test::{black_box, Bencher, TestDesc, TestDescAndFn};
18-
use test::{DynTestName, DynBenchFn, TDynBenchFn};
18+
use test::{DynBenchFn, DynTestName, TDynBenchFn};
1919

20-
use html5ever::tokenizer::{BufferQueue, TokenSink, Token, Tokenizer, TokenizerOpts, TokenSinkResult};
2120
use html5ever::tendril::*;
21+
use html5ever::tokenizer::{
22+
BufferQueue, Token, TokenSink, TokenSinkResult, Tokenizer, TokenizerOpts,
23+
};
2224

2325
struct Sink;
2426

@@ -45,16 +47,17 @@ struct Bench {
4547
unsafe impl Send for Bench {}
4648

4749
impl Bench {
48-
fn new(name: &str, size: Option<usize>, clone_only: bool,
49-
opts: TokenizerOpts) -> Bench {
50+
fn new(name: &str, size: Option<usize>, clone_only: bool, opts: TokenizerOpts) -> Bench {
5051
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
5152
path.push("data/bench/");
5253
path.push(name);
5354
let mut file = fs::File::open(&path).ok().expect("can't open file");
5455

5556
// Read the file and treat it as an infinitely repeating sequence of characters.
5657
let mut file_input = ByteTendril::new();
57-
file.read_to_tendril(&mut file_input).ok().expect("can't read file");
58+
file.read_to_tendril(&mut file_input)
59+
.ok()
60+
.expect("can't read file");
5861
let file_input: StrTendril = file_input.try_reinterpret().unwrap();
5962
let size = size.unwrap_or(file_input.len());
6063
let mut stream = file_input.chars().cycle();
@@ -104,39 +107,60 @@ impl TDynBenchFn for Bench {
104107
}
105108
}
106109

107-
fn make_bench(name: &str, size: Option<usize>, clone_only: bool,
108-
opts: TokenizerOpts) -> TestDescAndFn {
110+
fn make_bench(
111+
name: &str,
112+
size: Option<usize>,
113+
clone_only: bool,
114+
opts: TokenizerOpts,
115+
) -> TestDescAndFn {
109116
TestDescAndFn {
110-
desc: TestDesc::new(DynTestName([
111-
"tokenize ".to_string(),
112-
name.to_string(),
113-
size.map_or("".to_string(), |s| format!(" size {:7}", s)),
114-
(if clone_only { " (clone only)" } else { "" }).to_string(),
115-
(if opts.exact_errors { " (exact errors)" } else { "" }).to_string(),
116-
].concat().to_string())),
117+
desc: TestDesc::new(DynTestName(
118+
[
119+
"tokenize ".to_string(),
120+
name.to_string(),
121+
size.map_or("".to_string(), |s| format!(" size {:7}", s)),
122+
(if clone_only { " (clone only)" } else { "" }).to_string(),
123+
(if opts.exact_errors {
124+
" (exact errors)"
125+
} else {
126+
""
127+
}).to_string(),
128+
].concat()
129+
.to_string(),
130+
)),
117131
testfn: DynBenchFn(Box::new(Bench::new(name, size, clone_only, opts))),
118132
}
119133
}
120134

121135
fn tests() -> Vec<TestDescAndFn> {
122-
let mut tests = vec!(make_bench("lipsum.html", Some(1024*1024), true, Default::default()));
123-
124-
let mut opts_vec = vec!(Default::default());
136+
let mut tests = vec![make_bench(
137+
"lipsum.html",
138+
Some(1024 * 1024),
139+
true,
140+
Default::default(),
141+
)];
142+
143+
let mut opts_vec = vec![Default::default()];
125144
if env::var("BENCH_EXACT_ERRORS").is_ok() {
126145
opts_vec.push(TokenizerOpts {
127146
exact_errors: true,
128-
.. Default::default()
147+
..Default::default()
129148
});
130149
}
131150

132151
for opts in opts_vec.iter() {
133152
for &file in ["lipsum.html", "lipsum-zh.html", "strong.html"].iter() {
134-
for &sz in [1024, 1024*1024].iter() {
153+
for &sz in [1024, 1024 * 1024].iter() {
135154
tests.push(make_bench(file, Some(sz), false, opts.clone()));
136155
}
137156
}
138157

139-
for &file in ["tiny-fragment.html", "small-fragment.html", "medium-fragment.html"].iter() {
158+
for &file in [
159+
"tiny-fragment.html",
160+
"small-fragment.html",
161+
"medium-fragment.html",
162+
].iter()
163+
{
140164
tests.push(make_bench(file, None, false, opts.clone()));
141165
}
142166

html5ever/build.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
#[macro_use] extern crate quote;
11-
#[macro_use] extern crate syn;
10+
#[macro_use]
11+
extern crate quote;
12+
#[macro_use]
13+
extern crate syn;
1214
extern crate proc_macro2;
1315

1416
use std::env;
@@ -26,9 +28,12 @@ fn main() {
2628
println!("cargo:rerun-if-changed={}", input.display());
2729

2830
// We have stack overflows on Servo's CI.
29-
let handle = Builder::new().stack_size(128 * 1024 * 1024).spawn(move || {
30-
match_token::expand(&input, &output);
31-
}).unwrap();
31+
let handle = Builder::new()
32+
.stack_size(128 * 1024 * 1024)
33+
.spawn(move || {
34+
match_token::expand(&input, &output);
35+
})
36+
.unwrap();
3237

3338
handle.join().unwrap();
3439
}

html5ever/examples/arena.rs

Lines changed: 67 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
extern crate html5ever;
1111
extern crate typed_arena;
1212

13-
use html5ever::{parse_document, QualName, Attribute, ExpandedName};
14-
use html5ever::tendril::{TendrilSink, StrTendril};
15-
use html5ever::interface::tree_builder::{TreeSink, QuirksMode, NodeOrText, ElementFlags};
13+
use html5ever::interface::tree_builder::{ElementFlags, NodeOrText, QuirksMode, TreeSink};
14+
use html5ever::tendril::{StrTendril, TendrilSink};
15+
use html5ever::{parse_document, Attribute, ExpandedName, QualName};
1616
use std::borrow::Cow;
1717
use std::cell::{Cell, RefCell};
1818
use std::collections::HashSet;
@@ -32,7 +32,9 @@ fn html5ever_parse_slice_into_arena<'a>(bytes: &[u8], arena: Arena<'a>) -> Ref<'
3232
document: arena.alloc(Node::new(NodeData::Document)),
3333
quirks_mode: QuirksMode::NoQuirks,
3434
};
35-
parse_document(sink, Default::default()).from_utf8().one(bytes)
35+
parse_document(sink, Default::default())
36+
.from_utf8()
37+
.one(bytes)
3638
}
3739

3840
type Arena<'arena> = &'arena typed_arena::Arena<Node<'arena>>;
@@ -131,7 +133,10 @@ impl<'arena> Node<'arena> {
131133
new_sibling.next_sibling.set(Some(self));
132134
if let Some(previous_sibling) = self.previous_sibling.take() {
133135
new_sibling.previous_sibling.set(Some(previous_sibling));
134-
debug_assert!(ptr::eq::<Node>(previous_sibling.next_sibling.get().unwrap(), self));
136+
debug_assert!(ptr::eq::<Node>(
137+
previous_sibling.next_sibling.get().unwrap(),
138+
self
139+
));
135140
previous_sibling.next_sibling.set(Some(new_sibling));
136141
} else if let Some(parent) = self.parent.get() {
137142
debug_assert!(ptr::eq::<Node>(parent.first_child.get().unwrap(), self));
@@ -147,19 +152,26 @@ impl<'arena> Sink<'arena> {
147152
}
148153

149154
fn append_common<P, A>(&self, child: NodeOrText<Ref<'arena>>, previous: P, append: A)
150-
where P: FnOnce() -> Option<Ref<'arena>>,
151-
A: FnOnce(Ref<'arena>),
155+
where
156+
P: FnOnce() -> Option<Ref<'arena>>,
157+
A: FnOnce(Ref<'arena>),
152158
{
153159
let new_node = match child {
154160
NodeOrText::AppendText(text) => {
155161
// Append to an existing Text node if we have one.
156-
if let Some(&Node { data: NodeData::Text { ref contents }, .. }) = previous() {
162+
if let Some(&Node {
163+
data: NodeData::Text { ref contents },
164+
..
165+
}) = previous()
166+
{
157167
contents.borrow_mut().push_tendril(&text);
158-
return
168+
return;
159169
}
160-
self.new_node(NodeData::Text { contents: RefCell::new(text) })
170+
self.new_node(NodeData::Text {
171+
contents: RefCell::new(text),
172+
})
161173
}
162-
NodeOrText::AppendNode(node) => node
174+
NodeOrText::AppendNode(node) => node,
163175
};
164176

165177
append(new_node)
@@ -196,22 +208,35 @@ impl<'arena> TreeSink for Sink<'arena> {
196208
}
197209

198210
fn get_template_contents(&mut self, target: &Ref<'arena>) -> Ref<'arena> {
199-
if let NodeData::Element { template_contents: Some(ref contents), .. } = target.data {
211+
if let NodeData::Element {
212+
template_contents: Some(ref contents),
213+
..
214+
} = target.data
215+
{
200216
contents
201217
} else {
202218
panic!("not a template element!")
203219
}
204220
}
205221

206222
fn is_mathml_annotation_xml_integration_point(&self, target: &Ref<'arena>) -> bool {
207-
if let NodeData::Element { mathml_annotation_xml_integration_point, .. } = target.data {
223+
if let NodeData::Element {
224+
mathml_annotation_xml_integration_point,
225+
..
226+
} = target.data
227+
{
208228
mathml_annotation_xml_integration_point
209229
} else {
210230
panic!("not an element!")
211231
}
212232
}
213233

214-
fn create_element(&mut self, name: QualName, attrs: Vec<Attribute>, flags: ElementFlags) -> Ref<'arena> {
234+
fn create_element(
235+
&mut self,
236+
name: QualName,
237+
attrs: Vec<Attribute>,
238+
flags: ElementFlags,
239+
) -> Ref<'arena> {
215240
self.new_node(NodeData::Element {
216241
name: name,
217242
attrs: RefCell::new(attrs),
@@ -221,7 +246,6 @@ impl<'arena> TreeSink for Sink<'arena> {
221246
None
222247
},
223248
mathml_annotation_xml_integration_point: flags.mathml_annotation_xml_integration_point,
224-
225249
})
226250
}
227251

@@ -230,42 +254,51 @@ impl<'arena> TreeSink for Sink<'arena> {
230254
}
231255

232256
fn create_pi(&mut self, target: StrTendril, data: StrTendril) -> Ref<'arena> {
233-
self.new_node(NodeData::ProcessingInstruction { target: target, contents: data })
257+
self.new_node(NodeData::ProcessingInstruction {
258+
target: target,
259+
contents: data,
260+
})
234261
}
235262

236263
fn append(&mut self, parent: &Ref<'arena>, child: NodeOrText<Ref<'arena>>) {
237264
self.append_common(
238265
child,
239266
|| parent.last_child.get(),
240-
|new_node| parent.append(new_node)
267+
|new_node| parent.append(new_node),
241268
)
242269
}
243270

244271
fn append_before_sibling(&mut self, sibling: &Ref<'arena>, child: NodeOrText<Ref<'arena>>) {
245272
self.append_common(
246273
child,
247274
|| sibling.previous_sibling.get(),
248-
|new_node| sibling.insert_before(new_node)
275+
|new_node| sibling.insert_before(new_node),
249276
)
250277
}
251278

252-
fn append_based_on_parent_node(&mut self, element: &Ref<'arena>,
253-
prev_element: &Ref<'arena>, child: NodeOrText<Ref<'arena>>) {
279+
fn append_based_on_parent_node(
280+
&mut self,
281+
element: &Ref<'arena>,
282+
prev_element: &Ref<'arena>,
283+
child: NodeOrText<Ref<'arena>>,
284+
) {
254285
if element.parent.get().is_some() {
255286
self.append_before_sibling(element, child)
256287
} else {
257288
self.append(prev_element, child)
258289
}
259290
}
260291

261-
fn append_doctype_to_document(&mut self,
262-
name: StrTendril,
263-
public_id: StrTendril,
264-
system_id: StrTendril) {
292+
fn append_doctype_to_document(
293+
&mut self,
294+
name: StrTendril,
295+
public_id: StrTendril,
296+
system_id: StrTendril,
297+
) {
265298
self.document.append(self.new_node(NodeData::Doctype {
266299
name: name,
267300
public_id: public_id,
268-
system_id: system_id
301+
system_id: system_id,
269302
}))
270303
}
271304

@@ -276,10 +309,15 @@ impl<'arena> TreeSink for Sink<'arena> {
276309
panic!("not an element")
277310
};
278311

279-
let existing_names = existing.iter().map(|e| e.name.clone()).collect::<HashSet<_>>();
280-
existing.extend(attrs.into_iter().filter(|attr| {
281-
!existing_names.contains(&attr.name)
282-
}));
312+
let existing_names = existing
313+
.iter()
314+
.map(|e| e.name.clone())
315+
.collect::<HashSet<_>>();
316+
existing.extend(
317+
attrs
318+
.into_iter()
319+
.filter(|attr| !existing_names.contains(&attr.name)),
320+
);
283321
}
284322

285323
fn remove_from_parent(&mut self, target: &Ref<'arena>) {

html5ever/examples/html2html.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
1818
extern crate html5ever;
1919

20-
use std::io::{self, Write};
2120
use std::default::Default;
21+
use std::io::{self, Write};
2222

23-
24-
use html5ever::{parse_document, serialize};
2523
use html5ever::driver::ParseOpts;
2624
use html5ever::rcdom::RcDom;
2725
use html5ever::tendril::TendrilSink;
2826
use html5ever::tree_builder::TreeBuilderOpts;
27+
use html5ever::{parse_document, serialize};
2928

3029
fn main() {
3130
let opts = ParseOpts {
@@ -42,8 +41,11 @@ fn main() {
4241
.unwrap();
4342

4443
// The validator.nu HTML2HTML always prints a doctype at the very beginning.
45-
io::stdout().write_all(b"<!DOCTYPE html>\n")
46-
.ok().expect("writing DOCTYPE failed");
44+
io::stdout()
45+
.write_all(b"<!DOCTYPE html>\n")
46+
.ok()
47+
.expect("writing DOCTYPE failed");
4748
serialize(&mut io::stdout(), &dom.document, Default::default())
48-
.ok().expect("serialization failed");
49+
.ok()
50+
.expect("serialization failed");
4951
}

html5ever/examples/noop-tokenize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
extern crate html5ever;
1313

14-
use std::io;
1514
use std::default::Default;
15+
use std::io;
1616

17-
use html5ever::tokenizer::{BufferQueue, TokenSinkResult, TokenSink, Token, Tokenizer};
1817
use html5ever::tendril::*;
18+
use html5ever::tokenizer::{BufferQueue, Token, TokenSink, TokenSinkResult, Tokenizer};
1919

2020
struct Sink(Vec<Token>);
2121

0 commit comments

Comments
 (0)