servo: Merge #2407 - Avoid unnecessary allocations in try_parse_url (from Ms2ger:try_parse_url-owned); r=jdm

Source-Repo: https://github.com/servo/servo
Source-Revision: 3bb81310d4051c80cb9eec04a8382c95159de970
This commit is contained in:
Ms2ger 2014-05-12 14:55:22 -04:00
Родитель 65994af5bd
Коммит 95c7e74c0a
1 изменённых файлов: 3 добавлений и 3 удалений

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

@ -18,7 +18,7 @@ Create a URL object from a string. Does various helpful browsery things like
*/ */
// TODO: about:failure-> // TODO: about:failure->
pub fn try_parse_url(str_url: &str, base_url: Option<std_url::Url>) -> Result<std_url::Url, ~str> { pub fn try_parse_url(str_url: &str, base_url: Option<std_url::Url>) -> Result<std_url::Url, ~str> {
let str_url = str_url.trim_chars(& &[' ', '\t', '\n', '\r', '\x0C']).to_owned(); let str_url = str_url.trim_chars(& &[' ', '\t', '\n', '\r', '\x0C']);
let schm = std_url::get_scheme(str_url); let schm = std_url::get_scheme(str_url);
let str_url = match schm { let str_url = match schm {
Err(_) => { Err(_) => {
@ -69,7 +69,7 @@ pub fn try_parse_url(str_url: &str, base_url: Option<std_url::Url>) -> Result<st
"file://".to_owned() + path.display().to_str() "file://".to_owned() + path.display().to_str()
} }
// TODO: handle the rest of the about: pages // TODO: handle the rest of the about: pages
_ => str_url _ => str_url.to_owned()
} }
}, },
"data" => { "data" => {
@ -78,7 +78,7 @@ pub fn try_parse_url(str_url: &str, base_url: Option<std_url::Url>) -> Result<st
// %-encoded or base64'd. // %-encoded or base64'd.
str_url.chars().filter(|&c| !c.is_whitespace()).collect() str_url.chars().filter(|&c| !c.is_whitespace()).collect()
}, },
_ => str_url _ => str_url.to_owned()
} }
} }
}; };