diff --git a/components/gfx/platform/macos/font_template.rs b/components/gfx/platform/macos/font_template.rs index a98f60a95b2..cba1738b926 100644 --- a/components/gfx/platform/macos/font_template.rs +++ b/components/gfx/platform/macos/font_template.rs @@ -81,9 +81,8 @@ impl FontTemplateData { /// operation (depending on the platform) which performs synchronous disk I/O /// and should never be done lightly. pub fn bytes(&self) -> Vec { - match self.bytes_if_in_memory() { - Some(font_data) => return font_data, - None => {} + if let Some(font_data) = self.bytes_if_in_memory() { + return font_data; } let path = ServoUrl::parse(&*self.ctfont(0.0) diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs index f98f253881f..3a8a1171287 100644 --- a/components/layout/layout_debug.rs +++ b/components/layout/layout_debug.rs @@ -65,13 +65,10 @@ struct State { impl Scope { pub fn new(name: String) -> Scope { STATE_KEY.with(|ref r| { - match *r.borrow_mut() { - Some(ref mut state) => { - let flow_trace = to_value(&flow::base(&*state.flow_root)); - let data = box ScopeData::new(name.clone(), flow_trace); - state.scope_stack.push(data); - } - None => {} + if let Some(ref mut state) = *r.borrow_mut() { + let flow_trace = to_value(&flow::base(&*state.flow_root)); + let data = box ScopeData::new(name.clone(), flow_trace); + state.scope_stack.push(data); } }); Scope @@ -82,14 +79,11 @@ impl Scope { impl Drop for Scope { fn drop(&mut self) { STATE_KEY.with(|ref r| { - match *r.borrow_mut() { - Some(ref mut state) => { - let mut current_scope = state.scope_stack.pop().unwrap(); - current_scope.post = to_value(&flow::base(&*state.flow_root)); - let previous_scope = state.scope_stack.last_mut().unwrap(); - previous_scope.children.push(current_scope); - } - None => {} + if let Some(ref mut state) = *r.borrow_mut() { + let mut current_scope = state.scope_stack.pop().unwrap(); + current_scope.post = to_value(&flow::base(&*state.flow_root)); + let previous_scope = state.scope_stack.last_mut().unwrap(); + previous_scope.children.push(current_scope); } }); } diff --git a/components/net_traits/lib.rs b/components/net_traits/lib.rs index ac8ec07c2bb..14bbe5b5d23 100644 --- a/components/net_traits/lib.rs +++ b/components/net_traits/lib.rs @@ -438,24 +438,17 @@ impl Metadata { /// Extract the parts of a Mime that we care about. pub fn set_content_type(&mut self, content_type: Option<&Mime>) { - match self.headers { - None => self.headers = Some(Serde(Headers::new())), - Some(_) => (), + if self.headers.is_none() { + self.headers = Some(Serde(Headers::new())); } - match content_type { - None => (), - Some(mime) => { - if let Some(headers) = self.headers.as_mut() { - headers.set(ContentType(mime.clone())); - } - - 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()); - } + if let Some(mime) = content_type { + self.headers.as_mut().unwrap().set(ContentType(mime.clone())); + 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()); } } } diff --git a/components/profile/time.rs b/components/profile/time.rs index 8cb7c9502c3..c246aabee1b 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -296,12 +296,7 @@ impl Profiler { } fn find_or_insert(&mut self, k: (ProfilerCategory, Option), t: f64) { - match self.buckets.get_mut(&k) { - None => {}, - Some(v) => { v.push(t); return; }, - } - - self.buckets.insert(k, vec!(t)); + self.buckets.entry(k).or_insert_with(Vec::new).push(t); } fn handle_msg(&mut self, msg: ProfilerMsg) -> bool { diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 7556e64d0a7..cbc69b318df 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -155,20 +155,17 @@ impl DOMImplementationMethods for DOMImplementation { doc_html.AppendChild(&doc_head).unwrap(); // Step 6. - match title { - None => (), - Some(title_str) => { - // Step 6.1. - let doc_title = - Root::upcast::(HTMLTitleElement::new(local_name!("title"), - None, - &doc)); - doc_head.AppendChild(&doc_title).unwrap(); + if let Some(title_str) = title { + // Step 6.1. + let doc_title = + Root::upcast::(HTMLTitleElement::new(local_name!("title"), + None, + &doc)); + doc_head.AppendChild(&doc_title).unwrap(); - // Step 6.2. - let title_text = Text::new(title_str, &doc); - doc_title.AppendChild(title_text.upcast()).unwrap(); - } + // Step 6.2. + let title_text = Text::new(title_str, &doc); + doc_title.AppendChild(title_text.upcast()).unwrap(); } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index d5181e221fb..f01c51513ec 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -2663,15 +2663,11 @@ impl Element { self.set_enabled_state(false); return; } - match ancestor.children() - .find(|child| child.is::()) { - Some(ref legend) => { - // XXXabinader: should we save previous ancestor to avoid this iteration? - if node.ancestors().any(|ancestor| ancestor == *legend) { - continue; - } - }, - None => (), + if let Some(ref legend) = ancestor.children().find(|n| n.is::()) { + // XXXabinader: should we save previous ancestor to avoid this iteration? + if node.ancestors().any(|ancestor| ancestor == *legend) { + continue; + } } self.set_disabled_state(true); self.set_enabled_state(false); diff --git a/components/script/dom/eventdispatcher.rs b/components/script/dom/eventdispatcher.rs index d5e4bf51338..bdec56532dc 100644 --- a/components/script/dom/eventdispatcher.rs +++ b/components/script/dom/eventdispatcher.rs @@ -156,15 +156,11 @@ pub fn dispatch_event(target: &EventTarget, dispatch_to_listeners(event, target, event_path.r()); // Default action. - let target = event.GetTarget(); - match target { - Some(ref target) => { - if let Some(node) = target.downcast::() { - let vtable = vtable_for(&node); - vtable.handle_event(event); - } + if let Some(target) = event.GetTarget() { + if let Some(node) = target.downcast::() { + let vtable = vtable_for(&node); + vtable.handle_event(event); } - None => {} } // Step 10-12. diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 6a2ccea832f..d6bc301955d 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1792,9 +1792,8 @@ impl Node { pub fn collect_text_contents>>(iterator: T) -> DOMString { let mut content = String::new(); for node in iterator { - match node.downcast::() { - Some(ref text) => content.push_str(&text.upcast::().data()), - None => (), + if let Some(ref text) = node.downcast::() { + content.push_str(&text.upcast::().data()); } } DOMString::from(content) diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 538ce0b5f8c..447b6775bdc 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -498,13 +498,10 @@ impl<'a> ScriptMemoryFailsafe<'a> { impl<'a> Drop for ScriptMemoryFailsafe<'a> { #[allow(unrooted_must_root)] fn drop(&mut self) { - match self.owner { - Some(owner) => { - for (_, document) in owner.documents.borrow().iter() { - document.window().clear_js_runtime_for_script_deallocation(); - } + if let Some(owner) = self.owner { + for (_, document) in owner.documents.borrow().iter() { + document.window().clear_js_runtime_for_script_deallocation(); } - None => (), } } } @@ -725,10 +722,8 @@ impl ScriptThread { for (id, document) in self.documents.borrow().iter() { // Only process a resize if layout is idle. - let resize_event = document.window().steal_resize_event(); - match resize_event { - Some((size, size_type)) => resizes.push((id, size, size_type)), - None => () + if let Some((size, size_type)) = document.window().steal_resize_event() { + resizes.push((id, size, size_type)); } } diff --git a/components/style/thread_state.rs b/components/style/thread_state.rs index b0fbd5f4294..9f6dc5df8e8 100644 --- a/components/style/thread_state.rs +++ b/components/style/thread_state.rs @@ -60,10 +60,9 @@ mod imp { pub fn initialize(x: ThreadState) { STATE.with(|ref k| { - match *k.borrow() { - Some(s) => panic!("Thread state already initialized as {:?}", s), - None => () - }; + if let Some(ref s) = *k.borrow() { + panic!("Thread state already initialized as {:?}", s); + } *k.borrow_mut() = Some(x); }); get(); // check the assertion below diff --git a/ports/glutin/window.rs b/ports/glutin/window.rs index 11b77dafb60..bba97dad8f2 100644 --- a/ports/glutin/window.rs +++ b/ports/glutin/window.rs @@ -303,12 +303,9 @@ impl Window { fn nested_window_resize(width: u32, height: u32) { unsafe { - match G_NESTED_EVENT_LOOP_LISTENER { - None => {} - Some(listener) => { - (*listener).handle_event_from_nested_event_loop( - WindowEvent::Resize(TypedSize2D::new(width, height))); - } + if let Some(listener) = G_NESTED_EVENT_LOOP_LISTENER { + (*listener).handle_event_from_nested_event_loop( + WindowEvent::Resize(TypedSize2D::new(width, height))); } } }