Auto merge of #14728 - emilio:nit, r=Wafflespeanut

Bunch of nitpicks

I just noticed one while writing #14719, and then grepped and couldn't stop.

r? @nox

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14728)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-12-25 11:04:21 -08:00 committed by GitHub
commit 7fc9047d22
11 changed files with 53 additions and 93 deletions

View file

@ -81,9 +81,8 @@ impl FontTemplateData {
/// operation (depending on the platform) which performs synchronous disk I/O /// operation (depending on the platform) which performs synchronous disk I/O
/// and should never be done lightly. /// and should never be done lightly.
pub fn bytes(&self) -> Vec<u8> { pub fn bytes(&self) -> Vec<u8> {
match self.bytes_if_in_memory() { if let Some(font_data) = self.bytes_if_in_memory() {
Some(font_data) => return font_data, return font_data;
None => {}
} }
let path = ServoUrl::parse(&*self.ctfont(0.0) let path = ServoUrl::parse(&*self.ctfont(0.0)

View file

@ -65,13 +65,10 @@ struct State {
impl Scope { impl Scope {
pub fn new(name: String) -> Scope { pub fn new(name: String) -> Scope {
STATE_KEY.with(|ref r| { STATE_KEY.with(|ref r| {
match *r.borrow_mut() { if let Some(ref mut state) = *r.borrow_mut() {
Some(ref mut state) => { let flow_trace = to_value(&flow::base(&*state.flow_root));
let flow_trace = to_value(&flow::base(&*state.flow_root)); let data = box ScopeData::new(name.clone(), flow_trace);
let data = box ScopeData::new(name.clone(), flow_trace); state.scope_stack.push(data);
state.scope_stack.push(data);
}
None => {}
} }
}); });
Scope Scope
@ -82,14 +79,11 @@ impl Scope {
impl Drop for Scope { impl Drop for Scope {
fn drop(&mut self) { fn drop(&mut self) {
STATE_KEY.with(|ref r| { STATE_KEY.with(|ref r| {
match *r.borrow_mut() { if let Some(ref mut state) = *r.borrow_mut() {
Some(ref mut state) => { let mut current_scope = state.scope_stack.pop().unwrap();
let mut current_scope = state.scope_stack.pop().unwrap(); current_scope.post = to_value(&flow::base(&*state.flow_root));
current_scope.post = to_value(&flow::base(&*state.flow_root)); let previous_scope = state.scope_stack.last_mut().unwrap();
let previous_scope = state.scope_stack.last_mut().unwrap(); previous_scope.children.push(current_scope);
previous_scope.children.push(current_scope);
}
None => {}
} }
}); });
} }

View file

@ -438,24 +438,17 @@ impl Metadata {
/// Extract the parts of a Mime that we care about. /// Extract the parts of a Mime that we care about.
pub fn set_content_type(&mut self, content_type: Option<&Mime>) { pub fn set_content_type(&mut self, content_type: Option<&Mime>) {
match self.headers { if self.headers.is_none() {
None => self.headers = Some(Serde(Headers::new())), self.headers = Some(Serde(Headers::new()));
Some(_) => (),
} }
match content_type { if let Some(mime) = content_type {
None => (), self.headers.as_mut().unwrap().set(ContentType(mime.clone()));
Some(mime) => { self.content_type = Some(Serde(ContentType(mime.clone())));
if let Some(headers) = self.headers.as_mut() { let Mime(_, _, ref parameters) = *mime;
headers.set(ContentType(mime.clone())); for &(ref k, ref v) in parameters {
} if Attr::Charset == *k {
self.charset = Some(v.to_string());
self.content_type = Some(Serde(ContentType(mime.clone())));
let &Mime(_, _, ref parameters) = mime;
for &(ref k, ref v) in parameters {
if &Attr::Charset == k {
self.charset = Some(v.to_string());
}
} }
} }
} }

View file

@ -296,12 +296,7 @@ impl Profiler {
} }
fn find_or_insert(&mut self, k: (ProfilerCategory, Option<TimerMetadata>), t: f64) { fn find_or_insert(&mut self, k: (ProfilerCategory, Option<TimerMetadata>), t: f64) {
match self.buckets.get_mut(&k) { self.buckets.entry(k).or_insert_with(Vec::new).push(t);
None => {},
Some(v) => { v.push(t); return; },
}
self.buckets.insert(k, vec!(t));
} }
fn handle_msg(&mut self, msg: ProfilerMsg) -> bool { fn handle_msg(&mut self, msg: ProfilerMsg) -> bool {

View file

@ -155,20 +155,17 @@ impl DOMImplementationMethods for DOMImplementation {
doc_html.AppendChild(&doc_head).unwrap(); doc_html.AppendChild(&doc_head).unwrap();
// Step 6. // Step 6.
match title { if let Some(title_str) = title {
None => (), // Step 6.1.
Some(title_str) => { let doc_title =
// Step 6.1. Root::upcast::<Node>(HTMLTitleElement::new(local_name!("title"),
let doc_title = None,
Root::upcast::<Node>(HTMLTitleElement::new(local_name!("title"), &doc));
None, doc_head.AppendChild(&doc_title).unwrap();
&doc));
doc_head.AppendChild(&doc_title).unwrap();
// Step 6.2. // Step 6.2.
let title_text = Text::new(title_str, &doc); let title_text = Text::new(title_str, &doc);
doc_title.AppendChild(title_text.upcast()).unwrap(); doc_title.AppendChild(title_text.upcast()).unwrap();
}
} }
} }

View file

@ -2663,15 +2663,11 @@ impl Element {
self.set_enabled_state(false); self.set_enabled_state(false);
return; return;
} }
match ancestor.children() if let Some(ref legend) = ancestor.children().find(|n| n.is::<HTMLLegendElement>()) {
.find(|child| child.is::<HTMLLegendElement>()) { // XXXabinader: should we save previous ancestor to avoid this iteration?
Some(ref legend) => { if node.ancestors().any(|ancestor| ancestor == *legend) {
// XXXabinader: should we save previous ancestor to avoid this iteration? continue;
if node.ancestors().any(|ancestor| ancestor == *legend) { }
continue;
}
},
None => (),
} }
self.set_disabled_state(true); self.set_disabled_state(true);
self.set_enabled_state(false); self.set_enabled_state(false);

View file

@ -156,15 +156,11 @@ pub fn dispatch_event(target: &EventTarget,
dispatch_to_listeners(event, target, event_path.r()); dispatch_to_listeners(event, target, event_path.r());
// Default action. // Default action.
let target = event.GetTarget(); if let Some(target) = event.GetTarget() {
match target { if let Some(node) = target.downcast::<Node>() {
Some(ref target) => { let vtable = vtable_for(&node);
if let Some(node) = target.downcast::<Node>() { vtable.handle_event(event);
let vtable = vtable_for(&node);
vtable.handle_event(event);
}
} }
None => {}
} }
// Step 10-12. // Step 10-12.

View file

@ -1792,9 +1792,8 @@ impl Node {
pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> DOMString { pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> DOMString {
let mut content = String::new(); let mut content = String::new();
for node in iterator { for node in iterator {
match node.downcast::<Text>() { if let Some(ref text) = node.downcast::<Text>() {
Some(ref text) => content.push_str(&text.upcast::<CharacterData>().data()), content.push_str(&text.upcast::<CharacterData>().data());
None => (),
} }
} }
DOMString::from(content) DOMString::from(content)

View file

@ -498,13 +498,10 @@ impl<'a> ScriptMemoryFailsafe<'a> {
impl<'a> Drop for ScriptMemoryFailsafe<'a> { impl<'a> Drop for ScriptMemoryFailsafe<'a> {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
fn drop(&mut self) { fn drop(&mut self) {
match self.owner { if let Some(owner) = self.owner {
Some(owner) => { for (_, document) in owner.documents.borrow().iter() {
for (_, document) in owner.documents.borrow().iter() { document.window().clear_js_runtime_for_script_deallocation();
document.window().clear_js_runtime_for_script_deallocation();
}
} }
None => (),
} }
} }
} }
@ -725,10 +722,8 @@ impl ScriptThread {
for (id, document) in self.documents.borrow().iter() { for (id, document) in self.documents.borrow().iter() {
// Only process a resize if layout is idle. // Only process a resize if layout is idle.
let resize_event = document.window().steal_resize_event(); if let Some((size, size_type)) = document.window().steal_resize_event() {
match resize_event { resizes.push((id, size, size_type));
Some((size, size_type)) => resizes.push((id, size, size_type)),
None => ()
} }
} }

View file

@ -60,10 +60,9 @@ mod imp {
pub fn initialize(x: ThreadState) { pub fn initialize(x: ThreadState) {
STATE.with(|ref k| { STATE.with(|ref k| {
match *k.borrow() { if let Some(ref s) = *k.borrow() {
Some(s) => panic!("Thread state already initialized as {:?}", s), panic!("Thread state already initialized as {:?}", s);
None => () }
};
*k.borrow_mut() = Some(x); *k.borrow_mut() = Some(x);
}); });
get(); // check the assertion below get(); // check the assertion below

View file

@ -303,12 +303,9 @@ impl Window {
fn nested_window_resize(width: u32, height: u32) { fn nested_window_resize(width: u32, height: u32) {
unsafe { unsafe {
match G_NESTED_EVENT_LOOP_LISTENER { if let Some(listener) = G_NESTED_EVENT_LOOP_LISTENER {
None => {} (*listener).handle_event_from_nested_event_loop(
Some(listener) => { WindowEvent::Resize(TypedSize2D::new(width, height)));
(*listener).handle_event_from_nested_event_loop(
WindowEvent::Resize(TypedSize2D::new(width, height)));
}
} }
} }
} }