mirror of
https://github.com/servo/servo.git
synced 2025-06-23 00:24:35 +01:00
Reorder some comparisons to avoid allocating strings for them.
This commit is contained in:
parent
25542e3f7e
commit
0ff8610727
4 changed files with 39 additions and 39 deletions
|
@ -693,7 +693,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct ImagesFilter;
|
struct ImagesFilter;
|
||||||
impl CollectionFilter for ImagesFilter {
|
impl CollectionFilter for ImagesFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.deref().local_name == ~"img"
|
"img" == elem.deref().local_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~ImagesFilter;
|
let filter = ~ImagesFilter;
|
||||||
|
@ -707,7 +707,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct EmbedsFilter;
|
struct EmbedsFilter;
|
||||||
impl CollectionFilter for EmbedsFilter {
|
impl CollectionFilter for EmbedsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.deref().local_name == ~"embed"
|
"embed" == elem.deref().local_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~EmbedsFilter;
|
let filter = ~EmbedsFilter;
|
||||||
|
@ -726,7 +726,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct LinksFilter;
|
struct LinksFilter;
|
||||||
impl CollectionFilter for LinksFilter {
|
impl CollectionFilter for LinksFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
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()
|
elem.get_attribute(Null, "href").is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -741,7 +741,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct FormsFilter;
|
struct FormsFilter;
|
||||||
impl CollectionFilter for FormsFilter {
|
impl CollectionFilter for FormsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.deref().local_name == ~"form"
|
"form" == elem.deref().local_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~FormsFilter;
|
let filter = ~FormsFilter;
|
||||||
|
@ -755,7 +755,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct ScriptsFilter;
|
struct ScriptsFilter;
|
||||||
impl CollectionFilter for ScriptsFilter {
|
impl CollectionFilter for ScriptsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.deref().local_name == ~"script"
|
"script" == elem.deref().local_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~ScriptsFilter;
|
let filter = ~ScriptsFilter;
|
||||||
|
@ -769,7 +769,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct AnchorsFilter;
|
struct AnchorsFilter;
|
||||||
impl CollectionFilter for AnchorsFilter {
|
impl CollectionFilter for AnchorsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
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;
|
let filter = ~AnchorsFilter;
|
||||||
|
@ -783,7 +783,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
||||||
struct AppletsFilter;
|
struct AppletsFilter;
|
||||||
impl CollectionFilter for AppletsFilter {
|
impl CollectionFilter for AppletsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
||||||
elem.deref().local_name == ~"applet"
|
"applet" == elem.deref().local_name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filter = ~AppletsFilter;
|
let filter = ~AppletsFilter;
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> {
|
||||||
struct HTMLDataListOptionsFilter;
|
struct HTMLDataListOptionsFilter;
|
||||||
impl CollectionFilter for HTMLDataListOptionsFilter {
|
impl CollectionFilter for HTMLDataListOptionsFilter {
|
||||||
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
|
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);
|
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||||
|
|
|
@ -108,15 +108,15 @@ pub fn from_cmdline_args(args: &[~str]) -> Option<Opts> {
|
||||||
|
|
||||||
let render_backend = match opt_match.opt_str("r") {
|
let render_backend = match opt_match.opt_str("r") {
|
||||||
Some(backend_str) => {
|
Some(backend_str) => {
|
||||||
if backend_str == ~"direct2d" {
|
if "direct2d" == backend_str {
|
||||||
Direct2DBackend
|
Direct2DBackend
|
||||||
} else if backend_str == ~"core-graphics" {
|
} else if "core-graphics" == backend_str {
|
||||||
CoreGraphicsBackend
|
CoreGraphicsBackend
|
||||||
} else if backend_str == ~"core-graphics-accelerated" {
|
} else if "core-graphics-accelerated" == backend_str {
|
||||||
CoreGraphicsAcceleratedBackend
|
CoreGraphicsAcceleratedBackend
|
||||||
} else if backend_str == ~"cairo" {
|
} else if "cairo" == backend_str {
|
||||||
CairoBackend
|
CairoBackend
|
||||||
} else if backend_str == ~"skia" {
|
} else if "skia" == backend_str {
|
||||||
SkiaBackend
|
SkiaBackend
|
||||||
} else {
|
} else {
|
||||||
fail!("unknown backend type")
|
fail!("unknown backend type")
|
||||||
|
|
|
@ -98,7 +98,7 @@ mod parse_url_tests {
|
||||||
let file = "local.html";
|
let file = "local.html";
|
||||||
let url = parse_url(file, None);
|
let url = parse_url(file, None);
|
||||||
debug!("url: {:?}", url);
|
debug!("url: {:?}", url);
|
||||||
assert!(url.scheme == ~"file");
|
assert!("file" == url.scheme);
|
||||||
let path = os::getcwd();
|
let path = os::getcwd();
|
||||||
// FIXME (#1094): not the right way to transform a path
|
// FIXME (#1094): not the right way to transform a path
|
||||||
assert!(url.path.contains(path.display().to_str()));
|
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 old_url = parse_url(old_str, None);
|
||||||
let new_str = "index.html";
|
let new_str = "index.html";
|
||||||
let new_url = parse_url(new_str, Some(old_url));
|
let new_url = parse_url(new_str, Some(old_url));
|
||||||
assert!(new_url.scheme == ~"http");
|
assert!("http" == new_url.scheme);
|
||||||
assert!(new_url.host == ~"example.com");
|
assert!("example.com" == new_url.host);
|
||||||
assert!(new_url.path == ~"/index.html");
|
assert!("/index.html" == new_url.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -121,9 +121,9 @@ mod parse_url_tests {
|
||||||
let old_url = parse_url(old_str, None);
|
let old_url = parse_url(old_str, None);
|
||||||
let new_str = "index.html";
|
let new_str = "index.html";
|
||||||
let new_url = parse_url(new_str, Some(old_url));
|
let new_url = parse_url(new_str, Some(old_url));
|
||||||
assert!(new_url.scheme == ~"http");
|
assert!("http" == new_url.scheme);
|
||||||
assert!(new_url.host == ~"example.com");
|
assert!("example.com" == new_url.host);
|
||||||
assert!(new_url.path == ~"/index.html");
|
assert!("/index.html" == new_url.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -132,9 +132,9 @@ mod parse_url_tests {
|
||||||
let old_url = parse_url(old_str, None);
|
let old_url = parse_url(old_str, None);
|
||||||
let new_str = "crumpet.html";
|
let new_str = "crumpet.html";
|
||||||
let new_url = parse_url(new_str, Some(old_url));
|
let new_url = parse_url(new_str, Some(old_url));
|
||||||
assert!(new_url.scheme == ~"http");
|
assert!("http" == new_url.scheme);
|
||||||
assert!(new_url.host == ~"example.com");
|
assert!("example.com" == new_url.host);
|
||||||
assert!(new_url.path == ~"/crumpet.html");
|
assert!("/crumpet.html" == new_url.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -143,9 +143,9 @@ mod parse_url_tests {
|
||||||
let old_url = parse_url(old_str, None);
|
let old_url = parse_url(old_str, None);
|
||||||
let new_str = "crumpet.html";
|
let new_str = "crumpet.html";
|
||||||
let new_url = parse_url(new_str, Some(old_url));
|
let new_url = parse_url(new_str, Some(old_url));
|
||||||
assert!(new_url.scheme == ~"http");
|
assert!("http" == new_url.scheme);
|
||||||
assert!(new_url.host == ~"example.com");
|
assert!("example.com" == new_url.host);
|
||||||
assert!(new_url.path == ~"/snarf/crumpet.html");
|
assert!("/snarf/crumpet.html" == new_url.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -155,10 +155,10 @@ mod parse_url_tests {
|
||||||
let new_str = "#top";
|
let new_str = "#top";
|
||||||
let new_url = parse_url(new_str, Some(old_url));
|
let new_url = parse_url(new_str, Some(old_url));
|
||||||
|
|
||||||
assert!(new_url.scheme == ~"http");
|
assert!("http" == new_url.scheme);
|
||||||
assert!(new_url.host == ~"example.com");
|
assert!("example.com" == new_url.host);
|
||||||
assert!(new_url.path == ~"/index.html");
|
assert!("/index.html" == new_url.path);
|
||||||
assert!(new_url.fragment == Some(~"top"));
|
assert!(new_url.fragment == Some("top".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -170,12 +170,12 @@ mod parse_url_tests {
|
||||||
let new_str = "#top";
|
let new_str = "#top";
|
||||||
let new_url = parse_url(new_str, Some(old_url));
|
let new_url = parse_url(new_str, Some(old_url));
|
||||||
|
|
||||||
assert!(new_url.scheme == ~"http");
|
assert!("http" == new_url.scheme);
|
||||||
assert!(new_url.user == Some(UserInfo { user: ~"foo", pass: Some(~"bar") }));
|
assert!(new_url.user == Some(UserInfo { user: "foo".to_owned(), pass: Some("bar".to_owned()) }));
|
||||||
assert!(new_url.host == ~"example.com");
|
assert!("example.com" == new_url.host);
|
||||||
assert!(new_url.port == Some(~"8080"));
|
assert!(new_url.port == Some("8080".to_owned()));
|
||||||
assert!(new_url.path == ~"/index.html");
|
assert!("/index.html" == new_url.path);
|
||||||
assert!(new_url.fragment == Some(~"top"));
|
assert!(new_url.fragment == Some("top".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -184,9 +184,9 @@ mod parse_url_tests {
|
||||||
let old_url = parse_url(old_str, None);
|
let old_url = parse_url(old_str, None);
|
||||||
let new_str = "//example.com/crumpet.html";
|
let new_str = "//example.com/crumpet.html";
|
||||||
let new_url = parse_url(new_str, Some(old_url));
|
let new_url = parse_url(new_str, Some(old_url));
|
||||||
assert!(new_url.scheme == ~"https");
|
assert!("https" == new_url.scheme);
|
||||||
assert!(new_url.host == ~"example.com");
|
assert!("example.com" == new_url.host);
|
||||||
assert!(new_url.path == ~"/crumpet.html");
|
assert!("/crumpet.html" == new_url.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue