Clean up Area::parse (#15834)

Replace mutable reference to array with direct use

Remove unecessary clone

Replace call to unwrap()
This commit is contained in:
Omar Akkila 2017-07-06 13:32:40 +04:00
parent 7323c7745c
commit 186d15edc2

View file

@ -24,6 +24,7 @@ use html5ever::{LocalName, Prefix};
use net_traits::ReferrerPolicy; use net_traits::ReferrerPolicy;
use std::default::Default; use std::default::Default;
use std::f32; use std::f32;
use std::str;
use style::attr::AttrValue; use style::attr::AttrValue;
#[derive(PartialEq)] #[derive(PartialEq)]
@ -68,7 +69,6 @@ impl Area {
//This vector will hold all parsed coordinates //This vector will hold all parsed coordinates
let mut number_list = Vec::new(); let mut number_list = Vec::new();
let mut array = Vec::new(); let mut array = Vec::new();
let ar_ref = &mut array;
// Step 5: walk till end of string // Step 5: walk till end of string
while index < size { while index < size {
@ -89,24 +89,24 @@ impl Area {
match val { match val {
b',' | b';' | b' ' | b'\t' | b'\n' | 0x0C | b'\r' => break, b',' | b';' | b' ' | b'\t' | b'\n' | 0x0C | b'\r' => break,
_ => (*ar_ref).push(val), _ => array.push(val),
} }
index += 1; index += 1;
} }
// The input does not consist any valid charecters // The input does not consist any valid charecters
if (*ar_ref).is_empty() { if array.is_empty() {
break; break;
} }
// Convert String to float // Convert String to float
match String::from_utf8((*ar_ref).clone()).unwrap().parse::<f32>() { match str::from_utf8(&array).ok().and_then(|s| s.parse::<f32>().ok()) {
Ok(v) => number_list.push(v), Some(v) => number_list.push(v),
Err(_) => number_list.push(0.0), None => number_list.push(0.0),
}; };
(*ar_ref).clear(); array.clear();
// For rectangle and circle, stop parsing once we have three // For rectangle and circle, stop parsing once we have three
// and four coordinates respectively // and four coordinates respectively