Skip to content

Commit 12b4ce0

Browse files
committed
Run rustfmt on everything
1 parent bfca145 commit 12b4ce0

Some content is hidden

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

56 files changed

+2989
-2161
lines changed

html5ever/benches/html5ever.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ extern crate html5ever;
55
use std::fs;
66
use std::path::PathBuf;
77

8-
use criterion::{Criterion, black_box};
8+
use criterion::{black_box, Criterion};
99

10-
use html5ever::tokenizer::{BufferQueue, TokenSink, Token, Tokenizer, TokenizerOpts, TokenSinkResult};
1110
use html5ever::tendril::*;
11+
use html5ever::tokenizer::{
12+
BufferQueue, Token, TokenSink, TokenSinkResult, Tokenizer, TokenizerOpts,
13+
};
1214

1315
struct Sink;
1416

@@ -23,7 +25,6 @@ impl TokenSink for Sink {
2325
}
2426
}
2527

26-
2728
fn run_bench(c: &mut Criterion, name: &str) {
2829
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
2930
path.push("data/bench/");
@@ -32,7 +33,9 @@ fn run_bench(c: &mut Criterion, name: &str) {
3233

3334
// Read the file and treat it as an infinitely repeating sequence of characters.
3435
let mut file_input = ByteTendril::new();
35-
file.read_to_tendril(&mut file_input).ok().expect("can't read file");
36+
file.read_to_tendril(&mut file_input)
37+
.ok()
38+
.expect("can't read file");
3639
let file_input: StrTendril = file_input.try_reinterpret().unwrap();
3740
let size = file_input.len();
3841
let mut stream = file_input.chars().cycle();
@@ -51,22 +54,22 @@ fn run_bench(c: &mut Criterion, name: &str) {
5154

5255
let test_name = format!("html tokenizing {}", name);
5356

54-
c.bench_function(&test_name, move |b| b.iter(|| {
55-
let mut tok = Tokenizer::new(Sink, Default::default());
56-
let mut buffer = BufferQueue::new();
57-
// We are doing clone inside the bench function, this is not ideal, but possibly
58-
// necessary since our iterator consumes the underlying buffer.
59-
for buf in input.clone().into_iter() {
60-
buffer.push_back(buf);
57+
c.bench_function(&test_name, move |b| {
58+
b.iter(|| {
59+
let mut tok = Tokenizer::new(Sink, Default::default());
60+
let mut buffer = BufferQueue::new();
61+
// We are doing clone inside the bench function, this is not ideal, but possibly
62+
// necessary since our iterator consumes the underlying buffer.
63+
for buf in input.clone().into_iter() {
64+
buffer.push_back(buf);
65+
let _ = tok.feed(&mut buffer);
66+
}
6167
let _ = tok.feed(&mut buffer);
62-
}
63-
let _ = tok.feed(&mut buffer);
64-
tok.end();
65-
}));
68+
tok.end();
69+
})
70+
});
6671
}
6772

68-
69-
7073
fn html5ever_benchmark(c: &mut Criterion) {
7174
run_bench(c, "lipsum.html");
7275
run_bench(c, "lipsum-zh.html");
@@ -77,4 +80,4 @@ fn html5ever_benchmark(c: &mut Criterion) {
7780
}
7881

7982
criterion_group!(benches, html5ever_benchmark);
80-
criterion_main!(benches);
83+
criterion_main!(benches);

html5ever/build.rs

+10-5
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

+68-30
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) })
161-
}
162-
NodeOrText::AppendNode(node) => node
170+
self.new_node(NodeData::Text {
171+
contents: RefCell::new(text),
172+
})
173+
},
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

+8-6
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

+2-2
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)