Remove some unnecessary uses of as_slice

For the majority of these cases, `as_slice` can be removed due to
`Deref`. In particular, `Deref` for:

* `String` -> `str`
* `Atom` -> `str`

The latter of those two requires, a bump of the locked `string-cache`
library
This commit is contained in:
Corey Farwell 2015-03-29 13:33:02 -04:00
parent b8ea10bfe3
commit d838fcce30
19 changed files with 98 additions and 102 deletions

View file

@ -171,7 +171,7 @@ impl CORSRequest {
}; };
// Substep 4 // Substep 4
if methods.len() == 0 || preflight.mode == RequestMode::ForcedPreflight { if methods.len() == 0 || preflight.mode == RequestMode::ForcedPreflight {
methods = methods_substep4.as_slice(); methods = &methods_substep4;
} }
// Substep 5 // Substep 5
if !is_simple_method(&self.method) && if !is_simple_method(&self.method) &&
@ -183,7 +183,7 @@ impl CORSRequest {
if is_simple_header(&h) { if is_simple_header(&h) {
continue; continue;
} }
if !headers.iter().any(|ref h2| h.name().eq_ignore_ascii_case(h2.as_slice())) { if !headers.iter().any(|ref h2| h.name().eq_ignore_ascii_case(h2)) {
return error; return error;
} }
} }
@ -254,7 +254,7 @@ pub enum HeaderOrMethod {
impl HeaderOrMethod { impl HeaderOrMethod {
fn match_header(&self, header_name: &str) -> bool { fn match_header(&self, header_name: &str) -> bool {
match *self { match *self {
HeaderOrMethod::HeaderData(ref s) => s.as_slice().eq_ignore_ascii_case(header_name), HeaderOrMethod::HeaderData(ref s) => s.eq_ignore_ascii_case(header_name),
_ => false _ => false
} }
} }

View file

@ -26,7 +26,7 @@ pub fn handle_evaluate_js(page: &Rc<Page>, pipeline: PipelineId, eval: String, r
let page = get_page(&*page, pipeline); let page = get_page(&*page, pipeline);
let window = page.window().root(); let window = page.window().root();
let cx = window.r().get_cx(); let cx = window.r().get_cx();
let rval = window.r().evaluate_js_on_global_with_result(eval.as_slice()); let rval = window.r().evaluate_js_on_global_with_result(&eval);
reply.send(if rval.is_undefined() { reply.send(if rval.is_undefined() {
EvaluateJSReply::VoidValue EvaluateJSReply::VoidValue
@ -69,7 +69,7 @@ fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String
let node: JSRef<Node> = NodeCast::from_ref(document.r()); let node: JSRef<Node> = NodeCast::from_ref(document.r());
for candidate in node.traverse_preorder() { for candidate in node.traverse_preorder() {
if candidate.get_unique_id().as_slice() == node_id.as_slice() { if candidate.get_unique_id() == node_id {
return Temporary::from_rooted(candidate); return Temporary::from_rooted(candidate);
} }
} }

View file

@ -78,7 +78,7 @@ impl Str for AttrValue {
AttrValue::String(ref value) | AttrValue::String(ref value) |
AttrValue::TokenList(ref value, _) | AttrValue::TokenList(ref value, _) |
AttrValue::UInt(ref value, _) => &value, AttrValue::UInt(ref value, _) => &value,
AttrValue::Atom(ref value) => value.as_slice(), AttrValue::Atom(ref value) => &value,
} }
} }
} }

View file

@ -24,7 +24,7 @@ impl ByteString {
/// otherwise. /// otherwise.
pub fn as_str<'a>(&'a self) -> Option<&'a str> { pub fn as_str<'a>(&'a self) -> Option<&'a str> {
let ByteString(ref vec) = *self; let ByteString(ref vec) = *self;
str::from_utf8(vec.as_slice()).ok() str::from_utf8(&vec).ok()
} }
/// Returns the underlying vector as a slice. /// Returns the underlying vector as a slice.

View file

@ -52,7 +52,7 @@ impl<'a> CanvasGradientMethods for JSRef<'a, CanvasGradient> {
self.stops.borrow_mut().push(CanvasGradientStop { self.stops.borrow_mut().push(CanvasGradientStop {
offset: (*offset) as f64, offset: (*offset) as f64,
color: parse_color(color.as_slice()).unwrap_or(default_black), color: parse_color(&color).unwrap_or(default_black),
}); });
} }
} }

View file

@ -493,7 +493,7 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
fn SetStrokeStyle(self, value: StringOrCanvasGradientOrCanvasPattern) { fn SetStrokeStyle(self, value: StringOrCanvasGradientOrCanvasPattern) {
match value { match value {
StringOrCanvasGradientOrCanvasPattern::eString(string) => { StringOrCanvasGradientOrCanvasPattern::eString(string) => {
match parse_color(string.as_slice()) { match parse_color(&string) {
Ok(rgba) => { Ok(rgba) => {
self.stroke_color.set(rgba); self.stroke_color.set(rgba);
self.renderer self.renderer
@ -521,7 +521,7 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
fn SetFillStyle(self, value: StringOrCanvasGradientOrCanvasPattern) { fn SetFillStyle(self, value: StringOrCanvasGradientOrCanvasPattern) {
match value { match value {
StringOrCanvasGradientOrCanvasPattern::eString(string) => { StringOrCanvasGradientOrCanvasPattern::eString(string) => {
match parse_color(string.as_slice()) { match parse_color(&string) {
Ok(rgba) => { Ok(rgba) => {
self.fill_color.set(rgba); self.fill_color.set(rgba);
self.renderer self.renderer
@ -640,7 +640,7 @@ impl Drop for CanvasRenderingContext2D {
} }
pub fn parse_color(string: &str) -> Result<RGBA,()> { pub fn parse_color(string: &str) -> Result<RGBA,()> {
match CSSColor::parse(&mut Parser::new(string.as_slice())) { match CSSColor::parse(&mut Parser::new(&string)) {
Ok(CSSColor::RGBA(rgba)) => Ok(rgba), Ok(CSSColor::RGBA(rgba)) => Ok(rgba),
_ => Err(()), _ => Err(()),
} }

View file

@ -52,7 +52,7 @@ macro_rules! css_properties(
fn serialize_list(list: &Vec<PropertyDeclaration>) -> DOMString { fn serialize_list(list: &Vec<PropertyDeclaration>) -> DOMString {
let mut result = String::new(); let mut result = String::new();
for declaration in list.iter() { for declaration in list.iter() {
result.push_str(serialize_value(declaration).as_slice()); result.push_str(&serialize_value(declaration));
result.push_str(" "); result.push_str(" ");
} }
result result
@ -131,10 +131,10 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
// http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
fn GetPropertyValue(self, property: DOMString) -> DOMString { fn GetPropertyValue(self, property: DOMString) -> DOMString {
// Step 1 // Step 1
let property = Atom::from_slice(property.as_slice().to_ascii_lowercase().as_slice()); let property = Atom::from_slice(&property.to_ascii_lowercase());
// Step 2 // Step 2
let longhand_properties = longhands_from_shorthand(property.as_slice()); let longhand_properties = longhands_from_shorthand(&property);
if let Some(longhand_properties) = longhand_properties { if let Some(longhand_properties) = longhand_properties {
// Step 2.1 // Step 2.1
let mut list = vec!(); let mut list = vec!();
@ -142,7 +142,7 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
// Step 2.2 // Step 2.2
for longhand in longhand_properties.iter() { for longhand in longhand_properties.iter() {
// Step 2.2.1 // Step 2.2.1
let declaration = self.get_declaration(&Atom::from_slice(longhand.as_slice())); let declaration = self.get_declaration(&Atom::from_slice(&longhand));
// Step 2.2.2 & 2.2.3 // Step 2.2.2 & 2.2.3
match declaration { match declaration {
@ -166,15 +166,15 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
// http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority
fn GetPropertyPriority(self, property: DOMString) -> DOMString { fn GetPropertyPriority(self, property: DOMString) -> DOMString {
// Step 1 // Step 1
let property = Atom::from_slice(property.as_slice().to_ascii_lowercase().as_slice()); let property = Atom::from_slice(&property.to_ascii_lowercase());
// Step 2 // Step 2
let longhand_properties = longhands_from_shorthand(property.as_slice()); let longhand_properties = longhands_from_shorthand(&property);
if let Some(longhand_properties) = longhand_properties { if let Some(longhand_properties) = longhand_properties {
// Step 2.1 & 2.2 & 2.3 // Step 2.1 & 2.2 & 2.3
if longhand_properties.iter() if longhand_properties.iter()
.map(|longhand| self.GetPropertyPriority(longhand.clone())) .map(|longhand| self.GetPropertyPriority(longhand.clone()))
.all(|priority| priority.as_slice() == "important") { .all(|priority| priority == "important") {
return "important".to_owned(); return "important".to_owned();
} }
@ -196,10 +196,10 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
} }
// Step 2 // Step 2
let property = property.as_slice().to_ascii_lowercase(); let property = property.to_ascii_lowercase();
// Step 3 // Step 3
if !is_supported_property(property.as_slice()) { if !is_supported_property(&property) {
return Ok(()); return Ok(());
} }
@ -209,20 +209,19 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
} }
// Step 5 // Step 5
let priority = priority.as_slice().to_ascii_lowercase(); let priority = priority.to_ascii_lowercase();
if priority.as_slice() != "!important" && !priority.is_empty() { if priority != "!important" && !priority.is_empty() {
return Ok(()); return Ok(());
} }
// Step 6 // Step 6
let mut synthesized_declaration = String::from_str(property.as_slice()); let mut synthesized_declaration = String::from_str(&property);
synthesized_declaration.push_str(": "); synthesized_declaration.push_str(": ");
synthesized_declaration.push_str(value.as_slice()); synthesized_declaration.push_str(&value);
let owner = self.owner.root(); let owner = self.owner.root();
let window = window_from_node(owner.r()).root(); let window = window_from_node(owner.r()).root();
let decl_block = parse_style_attribute(synthesized_declaration.as_slice(), let decl_block = parse_style_attribute(&synthesized_declaration, &window.r().get_url());
&window.r().get_url());
// Step 7 // Step 7
if decl_block.normal.len() == 0 { if decl_block.normal.len() == 0 {
@ -253,23 +252,22 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
} }
// Step 2 // Step 2
let property = property.as_slice().to_ascii_lowercase(); let property = property.to_ascii_lowercase();
// Step 3 // Step 3
if !is_supported_property(property.as_slice()) { if !is_supported_property(&property) {
return Ok(()); return Ok(());
} }
// Step 4 // Step 4
let priority = priority.as_slice().to_ascii_lowercase(); let priority = priority.to_ascii_lowercase();
if priority.as_slice() != "important" && !priority.is_empty() { if priority != "important" && !priority.is_empty() {
return Ok(()); return Ok(());
} }
let owner = self.owner.root(); let owner = self.owner.root();
let window = window_from_node(owner.r()).root(); let window = window_from_node(owner.r()).root();
let decl_block = parse_style_attribute(property.as_slice(), let decl_block = parse_style_attribute(&property, &window.r().get_url());
&window.r().get_url());
let element: JSRef<Element> = ElementCast::from_ref(owner.r()); let element: JSRef<Element> = ElementCast::from_ref(owner.r());
// Step 5 // Step 5
@ -298,12 +296,12 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> {
} }
// Step 2 // Step 2
let property = property.as_slice().to_ascii_lowercase(); let property = property.to_ascii_lowercase();
// Step 3 // Step 3
let value = self.GetPropertyValue(property.clone()); let value = self.GetPropertyValue(property.clone());
let longhand_properties = longhands_from_shorthand(property.as_slice()); let longhand_properties = longhands_from_shorthand(&property);
match longhand_properties { match longhand_properties {
Some(longhands) => { Some(longhands) => {
// Step 4 // Step 4

View file

@ -323,7 +323,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
let node: JSRef<Node> = NodeCast::from_ref(element); let node: JSRef<Node> = NodeCast::from_ref(element);
node.is_in_doc() node.is_in_doc()
}); });
assert!(!id.as_slice().is_empty()); assert!(!id.is_empty());
let mut idmap = self.idmap.borrow_mut(); let mut idmap = self.idmap.borrow_mut();

View file

@ -53,7 +53,7 @@ impl DOMImplementation {
impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
// http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype // http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype
fn CreateDocumentType(self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible<Temporary<DocumentType>> { fn CreateDocumentType(self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible<Temporary<DocumentType>> {
match xml_name_type(qname.as_slice()) { match xml_name_type(&qname) {
// Step 1. // Step 1.
InvalidXMLName => Err(InvalidCharacter), InvalidXMLName => Err(InvalidCharacter),
// Step 2. // Step 2.

View file

@ -94,7 +94,7 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
// http://dom.spec.whatwg.org/#dom-domtokenlist-contains // http://dom.spec.whatwg.org/#dom-domtokenlist-contains
fn Contains(self, token: DOMString) -> Fallible<bool> { fn Contains(self, token: DOMString) -> Fallible<bool> {
self.check_token_exceptions(token.as_slice()).map(|token| { self.check_token_exceptions(&token).map(|token| {
self.attribute().root().map(|attr| { self.attribute().root().map(|attr| {
// FIXME(https://github.com/rust-lang/rust/issues/23338) // FIXME(https://github.com/rust-lang/rust/issues/23338)
let attr = attr.r(); let attr = attr.r();
@ -112,7 +112,7 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
let element = self.element.root(); let element = self.element.root();
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name); let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
for token in tokens.iter() { for token in tokens.iter() {
let token = try!(self.check_token_exceptions(token.as_slice())); let token = try!(self.check_token_exceptions(&token));
if !atoms.iter().any(|atom| *atom == token) { if !atoms.iter().any(|atom| *atom == token) {
atoms.push(token); atoms.push(token);
} }
@ -126,7 +126,7 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
let element = self.element.root(); let element = self.element.root();
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name); let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
for token in tokens.iter() { for token in tokens.iter() {
let token = try!(self.check_token_exceptions(token.as_slice())); let token = try!(self.check_token_exceptions(&token));
atoms.iter().position(|atom| *atom == token).map(|index| { atoms.iter().position(|atom| *atom == token).map(|index| {
atoms.remove(index) atoms.remove(index)
}); });
@ -139,7 +139,7 @@ impl<'a> DOMTokenListMethods for JSRef<'a, DOMTokenList> {
fn Toggle(self, token: DOMString, force: Option<bool>) -> Fallible<bool> { fn Toggle(self, token: DOMString, force: Option<bool>) -> Fallible<bool> {
let element = self.element.root(); let element = self.element.root();
let mut atoms = element.r().get_tokenlist_attribute(&self.local_name); let mut atoms = element.r().get_tokenlist_attribute(&self.local_name);
let token = try!(self.check_token_exceptions(token.as_slice())); let token = try!(self.check_token_exceptions(&token));
match atoms.iter().position(|atom| *atom == token) { match atoms.iter().position(|atom| *atom == token) {
Some(index) => match force { Some(index) => match force {
Some(true) => Ok(true), Some(true) => Ok(true),

View file

@ -567,7 +567,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
declarations.normal declarations.normal
.iter() .iter()
.chain(declarations.important.iter()) .chain(declarations.important.iter())
.find(|decl| decl.matches(property.as_slice())) .find(|decl| decl.matches(&property))
.map(|decl| decl.clone()) .map(|decl| decl.clone())
}) })
} }
@ -577,7 +577,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
inline_declarations.as_ref().and_then(|declarations| { inline_declarations.as_ref().and_then(|declarations| {
declarations.important declarations.important
.iter() .iter()
.find(|decl| decl.matches(property.as_slice())) .find(|decl| decl.matches(&property))
.map(|decl| decl.clone()) .map(|decl| decl.clone())
}) })
} }
@ -680,7 +680,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
None => qname.local.clone(), None => qname.local.clone(),
Some(ref prefix) => { Some(ref prefix) => {
let name = format!("{}:{}", *prefix, qname.local.as_slice()); let name = format!("{}:{}", *prefix, qname.local.as_slice());
Atom::from_slice(name.as_slice()) Atom::from_slice(&name)
}, },
}; };
let value = self.parse_attribute(&qname.ns, &qname.local, value); let value = self.parse_attribute(&qname.ns, &qname.local, value);
@ -688,8 +688,8 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
} }
fn set_attribute(self, name: &Atom, value: AttrValue) { fn set_attribute(self, name: &Atom, value: AttrValue) {
assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); assert!(name.as_slice() == name.to_ascii_lowercase());
assert!(!name.as_slice().contains(":")); assert!(!name.contains(":"));
self.do_set_attribute(name.clone(), value, name.clone(), self.do_set_attribute(name.clone(), value, name.clone(),
ns!(""), None, |attr| attr.local_name() == name); ns!(""), None, |attr| attr.local_name() == name);
@ -698,7 +698,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
// https://html.spec.whatwg.org/multipage/dom.html#attr-data-* // https://html.spec.whatwg.org/multipage/dom.html#attr-data-*
fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult { fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult {
// Step 1. // Step 1.
match xml_name_type(name.as_slice()) { match xml_name_type(&name) {
InvalidXMLName => return Err(InvalidCharacter), InvalidXMLName => return Err(InvalidCharacter),
_ => {} _ => {}
} }
@ -785,7 +785,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
}; };
let is_equal = |lhs: &Atom, rhs: &Atom| match quirks_mode { let is_equal = |lhs: &Atom, rhs: &Atom| match quirks_mode {
NoQuirks | LimitedQuirks => lhs == rhs, NoQuirks | LimitedQuirks => lhs == rhs,
Quirks => lhs.as_slice().eq_ignore_ascii_case(rhs.as_slice()) Quirks => lhs.eq_ignore_ascii_case(&rhs)
}; };
self.get_attribute(ns!(""), &atom!("class")).root().map(|attr| { self.get_attribute(ns!(""), &atom!("class")).root().map(|attr| {
// FIXME(https://github.com/rust-lang/rust/issues/23338) // FIXME(https://github.com/rust-lang/rust/issues/23338)
@ -798,13 +798,13 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
} }
fn set_atomic_attribute(self, name: &Atom, value: DOMString) { fn set_atomic_attribute(self, name: &Atom, value: DOMString) {
assert!(name.as_slice().eq_ignore_ascii_case(name.as_slice())); assert!(name.eq_ignore_ascii_case(name));
let value = AttrValue::from_atomic(value); let value = AttrValue::from_atomic(value);
self.set_attribute(name, value); self.set_attribute(name, value);
} }
fn has_attribute(self, name: &Atom) -> bool { fn has_attribute(self, name: &Atom) -> bool {
assert!(name.as_slice().bytes().all(|b| b.to_ascii_lowercase() == b)); assert!(name.bytes().all(|b| b.to_ascii_lowercase() == b));
// FIXME(https://github.com/rust-lang/rust/issues/23338) // FIXME(https://github.com/rust-lang/rust/issues/23338)
let attrs = self.attrs.borrow(); let attrs = self.attrs.borrow();
attrs.iter().map(|attr| attr.root()).any(|attr| { attrs.iter().map(|attr| attr.root()).any(|attr| {
@ -821,12 +821,12 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
if value { if value {
self.set_string_attribute(name, String::new()); self.set_string_attribute(name, String::new());
} else { } else {
self.remove_attribute(ns!(""), name.as_slice()); self.remove_attribute(ns!(""), &name);
} }
} }
fn get_url_attribute(self, name: &Atom) -> DOMString { fn get_url_attribute(self, name: &Atom) -> DOMString {
assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); assert!(name.as_slice() == name.to_ascii_lowercase());
if !self.has_attribute(name) { if !self.has_attribute(name) {
return "".to_owned(); return "".to_owned();
} }
@ -835,7 +835,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
let base = doc.r().url(); let base = doc.r().url();
// https://html.spec.whatwg.org/multipage/infrastructure.html#reflect // https://html.spec.whatwg.org/multipage/infrastructure.html#reflect
// XXXManishearth this doesn't handle `javascript:` urls properly // XXXManishearth this doesn't handle `javascript:` urls properly
match UrlParser::new().base_url(&base).parse(url.as_slice()) { match UrlParser::new().base_url(&base).parse(&url) {
Ok(parsed) => parsed.serialize(), Ok(parsed) => parsed.serialize(),
Err(_) => "".to_owned() Err(_) => "".to_owned()
} }
@ -851,7 +851,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
} }
} }
fn set_string_attribute(self, name: &Atom, value: DOMString) { fn set_string_attribute(self, name: &Atom, value: DOMString) {
assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); assert!(name.as_slice() == name.to_ascii_lowercase());
self.set_attribute(name, AttrValue::String(value)); self.set_attribute(name, AttrValue::String(value));
} }
@ -867,17 +867,17 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
} }
fn set_tokenlist_attribute(self, name: &Atom, value: DOMString) { fn set_tokenlist_attribute(self, name: &Atom, value: DOMString) {
assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); assert!(name.as_slice() == name.to_ascii_lowercase());
self.set_attribute(name, AttrValue::from_serialized_tokenlist(value)); self.set_attribute(name, AttrValue::from_serialized_tokenlist(value));
} }
fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>) { fn set_atomic_tokenlist_attribute(self, name: &Atom, tokens: Vec<Atom>) {
assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); assert!(name.as_slice() == name.to_ascii_lowercase());
self.set_attribute(name, AttrValue::from_atomic_tokens(tokens)); self.set_attribute(name, AttrValue::from_atomic_tokens(tokens));
} }
fn get_uint_attribute(self, name: &Atom) -> u32 { fn get_uint_attribute(self, name: &Atom) -> u32 {
assert!(name.as_slice().chars().all(|ch| { assert!(name.chars().all(|ch| {
!ch.is_ascii() || ch.to_ascii_lowercase() == ch !ch.is_ascii() || ch.to_ascii_lowercase() == ch
})); }));
let attribute = self.get_attribute(ns!(""), name).root(); let attribute = self.get_attribute(ns!(""), name).root();
@ -893,7 +893,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
} }
} }
fn set_uint_attribute(self, name: &Atom, value: u32) { fn set_uint_attribute(self, name: &Atom, value: u32) {
assert!(name.as_slice() == name.as_slice().to_ascii_lowercase().as_slice()); assert!(name.as_slice() == name.to_ascii_lowercase());
self.set_attribute(name, AttrValue::UInt(value.to_string(), value)); self.set_attribute(name, AttrValue::UInt(value.to_string(), value));
} }
} }
@ -1382,7 +1382,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
let doc = document_from_node(*self).root(); let doc = document_from_node(*self).root();
let value = attr.r().Value(); let value = attr.r().Value();
if !value.is_empty() { if !value.is_empty() {
let value = Atom::from_slice(value.as_slice()); let value = Atom::from_slice(&value);
doc.r().register_named_element(*self, value); doc.r().register_named_element(*self, value);
} }
} }
@ -1399,7 +1399,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
let doc = document_from_node(*self).root(); let doc = document_from_node(*self).root();
let value = attr.r().Value(); let value = attr.r().Value();
if !value.is_empty() { if !value.is_empty() {
let value = Atom::from_slice(value.as_slice()); let value = Atom::from_slice(&value);
doc.r().unregister_named_element(*self, value); doc.r().unregister_named_element(*self, value);
} }
} }

View file

@ -76,7 +76,7 @@ impl HTMLCollection {
pub fn by_tag_name(window: JSRef<Window>, root: JSRef<Node>, tag: DOMString) pub fn by_tag_name(window: JSRef<Window>, root: JSRef<Node>, tag: DOMString)
-> Temporary<HTMLCollection> { -> Temporary<HTMLCollection> {
if tag.as_slice() == "*" { if tag == "*" {
return HTMLCollection::all_elements(window, root, None); return HTMLCollection::all_elements(window, root, None);
} }
@ -95,8 +95,8 @@ impl HTMLCollection {
} }
} }
let filter = TagNameFilter { let filter = TagNameFilter {
tag: Atom::from_slice(tag.as_slice()), tag: Atom::from_slice(&tag),
ascii_lower_tag: Atom::from_slice(tag.as_slice().to_ascii_lowercase().as_slice()), ascii_lower_tag: Atom::from_slice(&tag.to_ascii_lowercase()),
}; };
HTMLCollection::create(window, root, box filter) HTMLCollection::create(window, root, box filter)
} }
@ -104,11 +104,11 @@ impl HTMLCollection {
pub fn by_tag_name_ns(window: JSRef<Window>, root: JSRef<Node>, tag: DOMString, pub fn by_tag_name_ns(window: JSRef<Window>, root: JSRef<Node>, tag: DOMString,
maybe_ns: Option<DOMString>) -> Temporary<HTMLCollection> { maybe_ns: Option<DOMString>) -> Temporary<HTMLCollection> {
let namespace_filter = match maybe_ns { let namespace_filter = match maybe_ns {
Some(ref namespace) if namespace.as_slice() == "*" => None, Some(ref namespace) if namespace == &"*" => None,
ns => Some(namespace::from_domstring(ns)), ns => Some(namespace::from_domstring(ns)),
}; };
if tag.as_slice() == "*" { if tag == "*" {
return HTMLCollection::all_elements(window, root, namespace_filter); return HTMLCollection::all_elements(window, root, namespace_filter);
} }
#[jstraceable] #[jstraceable]
@ -128,7 +128,7 @@ impl HTMLCollection {
} }
} }
let filter = TagNameNSFilter { let filter = TagNameNSFilter {
tag: Atom::from_slice(tag.as_slice()), tag: Atom::from_slice(&tag),
namespace_filter: namespace_filter namespace_filter: namespace_filter
}; };
HTMLCollection::create(window, root, box filter) HTMLCollection::create(window, root, box filter)
@ -146,7 +146,7 @@ impl HTMLCollection {
} }
} }
let filter = ClassNameFilter { let filter = ClassNameFilter {
classes: split_html_space_chars(classes.as_slice()).map(|class| { classes: split_html_space_chars(&classes).map(|class| {
Atom::from_slice(class) Atom::from_slice(class)
}).collect() }).collect()
}; };

View file

@ -146,7 +146,7 @@ pub trait HTMLElementCustomAttributeHelpers {
fn to_snake_case(name: DOMString) -> DOMString { fn to_snake_case(name: DOMString) -> DOMString {
let mut attr_name = "data-".to_owned(); let mut attr_name = "data-".to_owned();
for ch in name.as_slice().chars() { for ch in name.chars() {
if ch.is_uppercase() { if ch.is_uppercase() {
attr_name.push('\x2d'); attr_name.push('\x2d');
attr_name.push(ch.to_lowercase()); attr_name.push(ch.to_lowercase());
@ -170,7 +170,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> {
fn get_custom_attr(self, name: DOMString) -> Option<DOMString> { fn get_custom_attr(self, name: DOMString) -> Option<DOMString> {
let element: JSRef<Element> = ElementCast::from_ref(self); let element: JSRef<Element> = ElementCast::from_ref(self);
element.get_attribute(ns!(""), &Atom::from_slice(to_snake_case(name).as_slice())).map(|attr| { element.get_attribute(ns!(""), &Atom::from_slice(&to_snake_case(name))).map(|attr| {
let attr = attr.root(); let attr = attr.root();
// FIXME(https://github.com/rust-lang/rust/issues/23338) // FIXME(https://github.com/rust-lang/rust/issues/23338)
let attr = attr.r(); let attr = attr.r();
@ -181,7 +181,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> {
fn delete_custom_attr(self, name: DOMString) { fn delete_custom_attr(self, name: DOMString) {
let element: JSRef<Element> = ElementCast::from_ref(self); let element: JSRef<Element> = ElementCast::from_ref(self);
element.remove_attribute(ns!(""), to_snake_case(name).as_slice()) element.remove_attribute(ns!(""), &to_snake_case(name))
} }
} }
@ -196,7 +196,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLElement> {
s.after_set_attr(attr); s.after_set_attr(attr);
} }
let name = attr.local_name().as_slice(); let name = attr.local_name();
if name.starts_with("on") { if name.starts_with("on") {
let window = window_from_node(*self).root(); let window = window_from_node(*self).root();
let (cx, url, reflector) = (window.r().get_cx(), let (cx, url, reflector) = (window.r().get_cx(),

View file

@ -218,8 +218,7 @@ impl Window {
} }
// http://www.whatwg.org/html/#atob // http://www.whatwg.org/html/#atob
pub fn base64_btoa(btoa: DOMString) -> Fallible<DOMString> { pub fn base64_btoa(input: DOMString) -> Fallible<DOMString> {
let input = btoa.as_slice();
// "The btoa() method must throw an InvalidCharacterError exception if // "The btoa() method must throw an InvalidCharacterError exception if
// the method's first argument contains any character whose code point // the method's first argument contains any character whose code point
// is greater than U+00FF." // is greater than U+00FF."
@ -239,10 +238,7 @@ pub fn base64_btoa(btoa: DOMString) -> Fallible<DOMString> {
} }
// http://www.whatwg.org/html/#atob // http://www.whatwg.org/html/#atob
pub fn base64_atob(atob: DOMString) -> Fallible<DOMString> { pub fn base64_atob(input: DOMString) -> Fallible<DOMString> {
// "Let input be the string being parsed."
let input = atob.as_slice();
// "Remove all space characters from input." // "Remove all space characters from input."
// serialize::base64::from_base64 ignores \r and \n, // serialize::base64::from_base64 ignores \r and \n,
// but it treats the other space characters as // but it treats the other space characters as

View file

@ -1074,7 +1074,7 @@ impl ScriptTask {
window: JS::from_rooted(window.r()), window: JS::from_rooted(window.r()),
})); }));
let is_javascript = incomplete.url.scheme.as_slice() == "javascript"; let is_javascript = incomplete.url.scheme == "javascript";
let parse_input = if is_javascript { let parse_input = if is_javascript {
let evalstr = incomplete.url.non_relative_scheme_data().unwrap(); let evalstr = incomplete.url.non_relative_scheme_data().unwrap();
let jsval = window.r().evaluate_js_on_global_with_result(evalstr); let jsval = window.r().evaluate_js_on_global_with_result(evalstr);
@ -1305,7 +1305,7 @@ impl ScriptTask {
let resource_task = self.resource_task.clone(); let resource_task = self.resource_task.clone();
spawn_named(format!("fetch for {:?}", load_data.url.serialize()), move || { spawn_named(format!("fetch for {:?}", load_data.url.serialize()), move || {
if load_data.url.scheme.as_slice() == "javascript" { if load_data.url.scheme == "javascript" {
load_data.url = Url::parse("about:blank").unwrap(); load_data.url = Url::parse("about:blank").unwrap();
} }

View file

@ -140,13 +140,13 @@ impl TextInput {
let lines_suffix = &self.lines[end.line + 1..]; let lines_suffix = &self.lines[end.line + 1..];
let mut insert_lines = if self.multiline { let mut insert_lines = if self.multiline {
insert.as_slice().split('\n').map(|s| s.to_owned()).collect() insert.split('\n').map(|s| s.to_owned()).collect()
} else { } else {
vec!(insert) vec!(insert)
}; };
let mut new_line = prefix.to_owned(); let mut new_line = prefix.to_owned();
new_line.push_str(insert_lines[0].as_slice()); new_line.push_str(&insert_lines[0]);
insert_lines[0] = new_line; insert_lines[0] = new_line;
let last_insert_lines_index = insert_lines.len() - 1; let last_insert_lines_index = insert_lines.len() - 1;
@ -157,7 +157,7 @@ impl TextInput {
let mut new_lines = vec!(); let mut new_lines = vec!();
new_lines.push_all(lines_prefix); new_lines.push_all(lines_prefix);
new_lines.push_all(insert_lines.as_slice()); new_lines.push_all(&insert_lines);
new_lines.push_all(lines_suffix); new_lines.push_all(lines_suffix);
new_lines new_lines
}; };
@ -341,7 +341,7 @@ impl TextInput {
pub fn get_content(&self) -> DOMString { pub fn get_content(&self) -> DOMString {
let mut content = "".to_owned(); let mut content = "".to_owned();
for (i, line) in self.lines.iter().enumerate() { for (i, line) in self.lines.iter().enumerate() {
content.push_str(line.as_slice()); content.push_str(&line);
if i < self.lines.len() - 1 { if i < self.lines.len() - 1 {
content.push('\n'); content.push('\n');
} }
@ -353,7 +353,7 @@ impl TextInput {
/// any \n encountered will be stripped and force a new logical line. /// any \n encountered will be stripped and force a new logical line.
pub fn set_content(&mut self, content: DOMString) { pub fn set_content(&mut self, content: DOMString) {
self.lines = if self.multiline { self.lines = if self.multiline {
content.as_slice().split('\n').map(|s| s.to_owned()).collect() content.split('\n').map(|s| s.to_owned()).collect()
} else { } else {
vec!(content) vec!(content)
}; };
@ -367,14 +367,14 @@ fn test_textinput_delete_char() {
let mut textinput = TextInput::new(Lines::Single, "abcdefg".to_owned()); let mut textinput = TextInput::new(Lines::Single, "abcdefg".to_owned());
textinput.adjust_horizontal(2, Selection::NotSelected); textinput.adjust_horizontal(2, Selection::NotSelected);
textinput.delete_char(DeleteDir::Backward); textinput.delete_char(DeleteDir::Backward);
assert_eq!(textinput.get_content().as_slice(), "acdefg"); assert_eq!(textinput.get_content(), "acdefg");
textinput.delete_char(DeleteDir::Forward); textinput.delete_char(DeleteDir::Forward);
assert_eq!(textinput.get_content().as_slice(), "adefg"); assert_eq!(textinput.get_content(), "adefg");
textinput.adjust_horizontal(2, Selection::Selected); textinput.adjust_horizontal(2, Selection::Selected);
textinput.delete_char(DeleteDir::Forward); textinput.delete_char(DeleteDir::Forward);
assert_eq!(textinput.get_content().as_slice(), "afg"); assert_eq!(textinput.get_content(), "afg");
} }
#[test] #[test]
@ -382,11 +382,11 @@ fn test_textinput_insert_char() {
let mut textinput = TextInput::new(Lines::Single, "abcdefg".to_owned()); let mut textinput = TextInput::new(Lines::Single, "abcdefg".to_owned());
textinput.adjust_horizontal(2, Selection::NotSelected); textinput.adjust_horizontal(2, Selection::NotSelected);
textinput.insert_char('a'); textinput.insert_char('a');
assert_eq!(textinput.get_content().as_slice(), "abacdefg"); assert_eq!(textinput.get_content(), "abacdefg");
textinput.adjust_horizontal(2, Selection::Selected); textinput.adjust_horizontal(2, Selection::Selected);
textinput.insert_char('b'); textinput.insert_char('b');
assert_eq!(textinput.get_content().as_slice(), "ababefg"); assert_eq!(textinput.get_content(), "ababefg");
} }
#[test] #[test]
@ -413,7 +413,7 @@ fn test_textinput_replace_selection() {
textinput.adjust_horizontal(2, Selection::Selected); textinput.adjust_horizontal(2, Selection::Selected);
textinput.replace_selection("xyz".to_owned()); textinput.replace_selection("xyz".to_owned());
assert_eq!(textinput.get_content().as_slice(), "abxyzefg"); assert_eq!(textinput.get_content(), "abxyzefg");
} }
#[test] #[test]
@ -470,12 +470,12 @@ fn test_textinput_handle_return() {
let mut single_line_textinput = TextInput::new(Lines::Single, "abcdef".to_owned()); let mut single_line_textinput = TextInput::new(Lines::Single, "abcdef".to_owned());
single_line_textinput.adjust_horizontal(3, Selection::NotSelected); single_line_textinput.adjust_horizontal(3, Selection::NotSelected);
single_line_textinput.handle_return(); single_line_textinput.handle_return();
assert_eq!(single_line_textinput.get_content().as_slice(), "abcdef"); assert_eq!(single_line_textinput.get_content(), "abcdef");
let mut multi_line_textinput = TextInput::new(Lines::Multiple, "abcdef".to_owned()); let mut multi_line_textinput = TextInput::new(Lines::Multiple, "abcdef".to_owned());
multi_line_textinput.adjust_horizontal(3, Selection::NotSelected); multi_line_textinput.adjust_horizontal(3, Selection::NotSelected);
multi_line_textinput.handle_return(); multi_line_textinput.handle_return();
assert_eq!(multi_line_textinput.get_content().as_slice(), "abc\ndef"); assert_eq!(multi_line_textinput.get_content(), "abc\ndef");
} }
#[test] #[test]
@ -492,19 +492,19 @@ fn test_textinput_select_all() {
#[test] #[test]
fn test_textinput_get_content() { fn test_textinput_get_content() {
let single_line_textinput = TextInput::new(Lines::Single, "abcdefg".to_owned()); let single_line_textinput = TextInput::new(Lines::Single, "abcdefg".to_owned());
assert_eq!(single_line_textinput.get_content().as_slice(), "abcdefg"); assert_eq!(single_line_textinput.get_content(), "abcdefg");
let multi_line_textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned()); let multi_line_textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned());
assert_eq!(multi_line_textinput.get_content().as_slice(), "abc\nde\nf"); assert_eq!(multi_line_textinput.get_content(), "abc\nde\nf");
} }
#[test] #[test]
fn test_textinput_set_content() { fn test_textinput_set_content() {
let mut textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned()); let mut textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".to_owned());
assert_eq!(textinput.get_content().as_slice(), "abc\nde\nf"); assert_eq!(textinput.get_content(), "abc\nde\nf");
textinput.set_content("abc\nf".to_owned()); textinput.set_content("abc\nf".to_owned());
assert_eq!(textinput.get_content().as_slice(), "abc\nf"); assert_eq!(textinput.get_content(), "abc\nf");
assert_eq!(textinput.edit_point.line, 0); assert_eq!(textinput.edit_point.line, 0);
assert_eq!(textinput.edit_point.index, 0); assert_eq!(textinput.edit_point.index, 0);
@ -512,7 +512,7 @@ fn test_textinput_set_content() {
assert_eq!(textinput.edit_point.line, 0); assert_eq!(textinput.edit_point.line, 0);
assert_eq!(textinput.edit_point.index, 3); assert_eq!(textinput.edit_point.index, 3);
textinput.set_content("de".to_owned()); textinput.set_content("de".to_owned());
assert_eq!(textinput.get_content().as_slice(), "de"); assert_eq!(textinput.get_content(), "de");
assert_eq!(textinput.edit_point.line, 0); assert_eq!(textinput.edit_point.line, 0);
assert_eq!(textinput.edit_point.index, 2); assert_eq!(textinput.edit_point.index, 2);
} }

View file

@ -815,7 +815,7 @@ source = "git+https://github.com/servo/rust-stb-image#b683cc9e7ba52a1bb65361347d
[[package]] [[package]]
name = "string_cache" name = "string_cache"
version = "0.0.0" version = "0.0.0"
source = "git+https://github.com/servo/string-cache#8c05fdf456a0e4f884e85d7e3a7700b2e4ca91eb" source = "git+https://github.com/servo/string-cache#124cb555651bd7838c5c6dc4788bc4f5350947a9"
dependencies = [ dependencies = [
"lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)",
"phf 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -827,7 +827,7 @@ dependencies = [
[[package]] [[package]]
name = "string_cache_plugin" name = "string_cache_plugin"
version = "0.0.0" version = "0.0.0"
source = "git+https://github.com/servo/string-cache#8c05fdf456a0e4f884e85d7e3a7700b2e4ca91eb" source = "git+https://github.com/servo/string-cache#124cb555651bd7838c5c6dc4788bc4f5350947a9"
dependencies = [ dependencies = [
"lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)",
"mac 0.0.2 (git+https://github.com/reem/rust-mac)", "mac 0.0.2 (git+https://github.com/reem/rust-mac)",

4
ports/cef/Cargo.lock generated
View file

@ -840,7 +840,7 @@ source = "git+https://github.com/servo/rust-stb-image#b683cc9e7ba52a1bb65361347d
[[package]] [[package]]
name = "string_cache" name = "string_cache"
version = "0.0.0" version = "0.0.0"
source = "git+https://github.com/servo/string-cache#8c05fdf456a0e4f884e85d7e3a7700b2e4ca91eb" source = "git+https://github.com/servo/string-cache#124cb555651bd7838c5c6dc4788bc4f5350947a9"
dependencies = [ dependencies = [
"lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)",
"phf 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -852,7 +852,7 @@ dependencies = [
[[package]] [[package]]
name = "string_cache_plugin" name = "string_cache_plugin"
version = "0.0.0" version = "0.0.0"
source = "git+https://github.com/servo/string-cache#8c05fdf456a0e4f884e85d7e3a7700b2e4ca91eb" source = "git+https://github.com/servo/string-cache#124cb555651bd7838c5c6dc4788bc4f5350947a9"
dependencies = [ dependencies = [
"lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)",
"mac 0.0.2 (git+https://github.com/reem/rust-mac)", "mac 0.0.2 (git+https://github.com/reem/rust-mac)",

6
ports/gonk/Cargo.lock generated
View file

@ -13,6 +13,7 @@ dependencies = [
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"msg 0.0.1", "msg 0.0.1",
"net 0.0.1", "net 0.0.1",
"profile 0.0.1",
"script 0.0.1", "script 0.0.1",
"servo 0.0.1", "servo 0.0.1",
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
@ -763,7 +764,7 @@ source = "git+https://github.com/servo/rust-stb-image#b683cc9e7ba52a1bb65361347d
[[package]] [[package]]
name = "string_cache" name = "string_cache"
version = "0.0.0" version = "0.0.0"
source = "git+https://github.com/servo/string-cache#8c05fdf456a0e4f884e85d7e3a7700b2e4ca91eb" source = "git+https://github.com/servo/string-cache#124cb555651bd7838c5c6dc4788bc4f5350947a9"
dependencies = [ dependencies = [
"lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)",
"phf 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -775,7 +776,7 @@ dependencies = [
[[package]] [[package]]
name = "string_cache_plugin" name = "string_cache_plugin"
version = "0.0.0" version = "0.0.0"
source = "git+https://github.com/servo/string-cache#8c05fdf456a0e4f884e85d7e3a7700b2e4ca91eb" source = "git+https://github.com/servo/string-cache#124cb555651bd7838c5c6dc4788bc4f5350947a9"
dependencies = [ dependencies = [
"lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)", "lazy_static 0.1.8 (git+https://github.com/Kimundi/lazy-static.rs)",
"mac 0.0.2 (git+https://github.com/reem/rust-mac)", "mac 0.0.2 (git+https://github.com/reem/rust-mac)",
@ -838,6 +839,7 @@ dependencies = [
name = "util" name = "util"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.2.0 (git+https://github.com/servo/rust-cssparser)", "cssparser 0.2.0 (git+https://github.com/servo/rust-cssparser)",
"geom 0.1.0 (git+https://github.com/servo/rust-geom)", "geom 0.1.0 (git+https://github.com/servo/rust-geom)",