Reorder some comparisons to avoid allocating strings for them.

This commit is contained in:
Ms2ger 2014-05-04 10:17:06 +02:00
parent 25542e3f7e
commit 0ff8610727
4 changed files with 39 additions and 39 deletions

View file

@ -693,7 +693,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
struct ImagesFilter;
impl CollectionFilter for ImagesFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
elem.deref().local_name == ~"img"
"img" == elem.deref().local_name
}
}
let filter = ~ImagesFilter;
@ -707,7 +707,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
struct EmbedsFilter;
impl CollectionFilter for EmbedsFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
elem.deref().local_name == ~"embed"
"embed" == elem.deref().local_name
}
}
let filter = ~EmbedsFilter;
@ -726,7 +726,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
struct LinksFilter;
impl CollectionFilter for LinksFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
(elem.deref().local_name == ~"a" || elem.deref().local_name == ~"area") &&
("a" == elem.deref().local_name || "area" == elem.deref().local_name) &&
elem.get_attribute(Null, "href").is_some()
}
}
@ -741,7 +741,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
struct FormsFilter;
impl CollectionFilter for FormsFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
elem.deref().local_name == ~"form"
"form" == elem.deref().local_name
}
}
let filter = ~FormsFilter;
@ -755,7 +755,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
struct ScriptsFilter;
impl CollectionFilter for ScriptsFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
elem.deref().local_name == ~"script"
"script" == elem.deref().local_name
}
}
let filter = ~ScriptsFilter;
@ -769,7 +769,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
struct AnchorsFilter;
impl CollectionFilter for AnchorsFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
elem.deref().local_name == ~"a" && elem.get_attribute(Null, "name").is_some()
"a" == elem.deref().local_name && elem.get_attribute(Null, "name").is_some()
}
}
let filter = ~AnchorsFilter;
@ -783,7 +783,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
struct AppletsFilter;
impl CollectionFilter for AppletsFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
elem.deref().local_name == ~"applet"
"applet" == elem.deref().local_name
}
}
let filter = ~AppletsFilter;

View file

@ -49,7 +49,7 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> {
struct HTMLDataListOptionsFilter;
impl CollectionFilter for HTMLDataListOptionsFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
elem.deref().local_name == ~"option"
"option" == elem.deref().local_name
}
}
let node: &JSRef<Node> = NodeCast::from_ref(self);

View file

@ -108,15 +108,15 @@ pub fn from_cmdline_args(args: &[~str]) -> Option<Opts> {
let render_backend = match opt_match.opt_str("r") {
Some(backend_str) => {
if backend_str == ~"direct2d" {
if "direct2d" == backend_str {
Direct2DBackend
} else if backend_str == ~"core-graphics" {
} else if "core-graphics" == backend_str {
CoreGraphicsBackend
} else if backend_str == ~"core-graphics-accelerated" {
} else if "core-graphics-accelerated" == backend_str {
CoreGraphicsAcceleratedBackend
} else if backend_str == ~"cairo" {
} else if "cairo" == backend_str {
CairoBackend
} else if backend_str == ~"skia" {
} else if "skia" == backend_str {
SkiaBackend
} else {
fail!("unknown backend type")

View file

@ -98,7 +98,7 @@ mod parse_url_tests {
let file = "local.html";
let url = parse_url(file, None);
debug!("url: {:?}", url);
assert!(url.scheme == ~"file");
assert!("file" == url.scheme);
let path = os::getcwd();
// FIXME (#1094): not the right way to transform a path
assert!(url.path.contains(path.display().to_str()));
@ -110,9 +110,9 @@ mod parse_url_tests {
let old_url = parse_url(old_str, None);
let new_str = "index.html";
let new_url = parse_url(new_str, Some(old_url));
assert!(new_url.scheme == ~"http");
assert!(new_url.host == ~"example.com");
assert!(new_url.path == ~"/index.html");
assert!("http" == new_url.scheme);
assert!("example.com" == new_url.host);
assert!("/index.html" == new_url.path);
}
#[test]
@ -121,9 +121,9 @@ mod parse_url_tests {
let old_url = parse_url(old_str, None);
let new_str = "index.html";
let new_url = parse_url(new_str, Some(old_url));
assert!(new_url.scheme == ~"http");
assert!(new_url.host == ~"example.com");
assert!(new_url.path == ~"/index.html");
assert!("http" == new_url.scheme);
assert!("example.com" == new_url.host);
assert!("/index.html" == new_url.path);
}
#[test]
@ -132,9 +132,9 @@ mod parse_url_tests {
let old_url = parse_url(old_str, None);
let new_str = "crumpet.html";
let new_url = parse_url(new_str, Some(old_url));
assert!(new_url.scheme == ~"http");
assert!(new_url.host == ~"example.com");
assert!(new_url.path == ~"/crumpet.html");
assert!("http" == new_url.scheme);
assert!("example.com" == new_url.host);
assert!("/crumpet.html" == new_url.path);
}
#[test]
@ -143,9 +143,9 @@ mod parse_url_tests {
let old_url = parse_url(old_str, None);
let new_str = "crumpet.html";
let new_url = parse_url(new_str, Some(old_url));
assert!(new_url.scheme == ~"http");
assert!(new_url.host == ~"example.com");
assert!(new_url.path == ~"/snarf/crumpet.html");
assert!("http" == new_url.scheme);
assert!("example.com" == new_url.host);
assert!("/snarf/crumpet.html" == new_url.path);
}
#[test]
@ -155,10 +155,10 @@ mod parse_url_tests {
let new_str = "#top";
let new_url = parse_url(new_str, Some(old_url));
assert!(new_url.scheme == ~"http");
assert!(new_url.host == ~"example.com");
assert!(new_url.path == ~"/index.html");
assert!(new_url.fragment == Some(~"top"));
assert!("http" == new_url.scheme);
assert!("example.com" == new_url.host);
assert!("/index.html" == new_url.path);
assert!(new_url.fragment == Some("top".to_owned()));
}
#[test]
@ -170,12 +170,12 @@ mod parse_url_tests {
let new_str = "#top";
let new_url = parse_url(new_str, Some(old_url));
assert!(new_url.scheme == ~"http");
assert!(new_url.user == Some(UserInfo { user: ~"foo", pass: Some(~"bar") }));
assert!(new_url.host == ~"example.com");
assert!(new_url.port == Some(~"8080"));
assert!(new_url.path == ~"/index.html");
assert!(new_url.fragment == Some(~"top"));
assert!("http" == new_url.scheme);
assert!(new_url.user == Some(UserInfo { user: "foo".to_owned(), pass: Some("bar".to_owned()) }));
assert!("example.com" == new_url.host);
assert!(new_url.port == Some("8080".to_owned()));
assert!("/index.html" == new_url.path);
assert!(new_url.fragment == Some("top".to_owned()));
}
#[test]
@ -184,9 +184,9 @@ mod parse_url_tests {
let old_url = parse_url(old_str, None);
let new_str = "//example.com/crumpet.html";
let new_url = parse_url(new_str, Some(old_url));
assert!(new_url.scheme == ~"https");
assert!(new_url.host == ~"example.com");
assert!(new_url.path == ~"/crumpet.html");
assert!("https" == new_url.scheme);
assert!("example.com" == new_url.host);
assert!("/crumpet.html" == new_url.path);
}
}