servo: Merge #14728 - Bunch of nitpicks (from emilio:nit); r=Wafflespeanut

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

r? @nox

Source-Repo: https://github.com/servo/servo
Source-Revision: 7fc9047d22147cf419d2551350421e23105e6f0e
This commit is contained in:
Emilio Cobos Álvarez 2016-12-25 11:04:21 -08:00
Родитель f459203bbf
Коммит 0c7e0c3aa5
11 изменённых файлов: 53 добавлений и 93 удалений

Просмотреть файл

@ -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<u8> {
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)

Просмотреть файл

@ -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);
}
});
}

Просмотреть файл

@ -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());
}
}
}

Просмотреть файл

@ -296,12 +296,7 @@ impl Profiler {
}
fn find_or_insert(&mut self, k: (ProfilerCategory, Option<TimerMetadata>), 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 {

Просмотреть файл

@ -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::<Node>(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::<Node>(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();
}
}

Просмотреть файл

@ -2663,15 +2663,11 @@ impl Element {
self.set_enabled_state(false);
return;
}
match ancestor.children()
.find(|child| child.is::<HTMLLegendElement>()) {
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::<HTMLLegendElement>()) {
// 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);

Просмотреть файл

@ -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::<Node>() {
let vtable = vtable_for(&node);
vtable.handle_event(event);
}
if let Some(target) = event.GetTarget() {
if let Some(node) = target.downcast::<Node>() {
let vtable = vtable_for(&node);
vtable.handle_event(event);
}
None => {}
}
// Step 10-12.

Просмотреть файл

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

Просмотреть файл

@ -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));
}
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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)));
}
}
}