From 755697d6bb0a316343a1e98a2d7f92f0d9eb7dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:20:30 +0100 Subject: [PATCH 01/12] script: Use more idiomatic code for resize handling. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Emilio Cobos Álvarez --- components/script/script_thread.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 538ce0b5f8c..82509d132c3 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -725,10 +725,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)); } } From d33ee4594dfe4e1a8592d498c0422effc06d17d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:26:03 +0100 Subject: [PATCH 02/12] net: Simplify content_type setter. --- components/net_traits/lib.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) 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()); } } } From d1b175d14511e630b22fa00e555b8ffe3fda43b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:27:31 +0100 Subject: [PATCH 03/12] script: Simplify DOMImplementation::CreateHTMLDocument. --- components/script/dom/domimplementation.rs | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) 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(); } } From 157ce33105c64d5b67a4aee24992fab47db8c111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:29:02 +0100 Subject: [PATCH 04/12] script: Simplify propagation of disabled state for form controls. That's a silly exponential algorithm btw. --- components/script/dom/element.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) 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); From 2bbde04ccdcfa0382bcfb69166ce1f7da2874ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:30:29 +0100 Subject: [PATCH 05/12] script: Simplify Node::collect_text_contents. --- components/script/dom/node.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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) From eaf69c29ec2c6952a925409e52529216315cf01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:31:32 +0100 Subject: [PATCH 06/12] script: Simplify ScriptMemoryFailsafe::drop. --- components/script/script_thread.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 82509d132c3..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 => (), } } } From 6264268c82d852ef86cb4308190dfb7f9468dcff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:32:35 +0100 Subject: [PATCH 07/12] style: Simplify initialization of thread_state. --- components/style/thread_state.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 From 39e082af180f16d9dcbcc6ea48a5bcfc684f7742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:34:42 +0100 Subject: [PATCH 08/12] gfx: Simplify OSX font template bytes accessor. --- components/gfx/platform/macos/font_template.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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) From cd00d65ffdf4430c07ad3a601a393afba6c2b3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:36:24 +0100 Subject: [PATCH 09/12] layout: Simplify layout debugging scope. --- components/layout/layout_debug.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) 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); } }); } From cc262c641fe6e882ce78c6377923e23d46398c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:37:41 +0100 Subject: [PATCH 10/12] script: Simplify EventDispatcher's default action. --- components/script/dom/eventdispatcher.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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. From ed87fcf6cfc692f316ecdd4752998ad567193e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:39:26 +0100 Subject: [PATCH 11/12] profile: Simplify profiler's find or insert code. --- components/profile/time.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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 { From f10e3765b1b0082fd8c0748221f2fae03bdbbb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 25 Dec 2016 17:42:07 +0100 Subject: [PATCH 12/12] glutin: Simplify set_nested_event_loop_listener. --- ports/glutin/window.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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))); } } }