diff options
author | Ms2ger <ms2ger@gmail.com> | 2015-04-25 15:24:27 +0200 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2015-04-25 15:24:27 +0200 |
commit | 41cc0a939e552f0898ab4cdeb7c4ebddb6378090 (patch) | |
tree | aea6fdde87c438b62a10c9a4e57a40f914925a44 | |
parent | 4108af0c113fcbd64abf2a1cf71026c2f7a653d3 (diff) | |
download | servo-41cc0a939e552f0898ab4cdeb7c4ebddb6378090.tar.gz servo-41cc0a939e552f0898ab4cdeb7c4ebddb6378090.zip |
Replace the Str implementation for AttrValue by a Deref implementation.
-rw-r--r-- | components/script/dom/attr.rs | 11 | ||||
-rw-r--r-- | components/script/dom/document.rs | 4 | ||||
-rw-r--r-- | components/script/dom/element.rs | 14 | ||||
-rw-r--r-- | components/script/dom/htmlbodyelement.rs | 4 | ||||
-rw-r--r-- | components/script/dom/htmlcanvaselement.rs | 4 | ||||
-rw-r--r-- | components/script/dom/htmlelement.rs | 4 | ||||
-rw-r--r-- | components/script/dom/htmliframeelement.rs | 4 | ||||
-rw-r--r-- | components/script/dom/htmlimageelement.rs | 2 | ||||
-rw-r--r-- | components/script/dom/htmlinputelement.rs | 8 | ||||
-rw-r--r-- | components/script/dom/htmllinkelement.rs | 4 | ||||
-rw-r--r-- | components/script/dom/htmltablecellelement.rs | 6 | ||||
-rw-r--r-- | components/script/dom/htmltableelement.rs | 7 | ||||
-rw-r--r-- | components/script/dom/htmltablerowelement.rs | 2 | ||||
-rw-r--r-- | components/script/dom/htmltablesectionelement.rs | 2 | ||||
-rw-r--r-- | components/script/dom/node.rs | 6 | ||||
-rw-r--r-- | components/script/parse/html.rs | 2 |
16 files changed, 43 insertions, 41 deletions
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs index 1820a854cd8..536600e5f34 100644 --- a/components/script/dom/attr.rs +++ b/components/script/dom/attr.rs @@ -23,6 +23,7 @@ use string_cache::{Atom, Namespace}; use std::borrow::ToOwned; use std::cell::Ref; use std::mem; +use std::ops::Deref; pub enum AttrSettingType { FirstSetAttr, @@ -79,8 +80,10 @@ impl AttrValue { } } -impl Str for AttrValue { - fn as_slice<'a>(&'a self) -> &'a str { +impl Deref for AttrValue { + type Target = str; + + fn deref<'a>(&'a self) -> &'a str { match *self { AttrValue::String(ref value) | AttrValue::TokenList(ref value, _) | @@ -151,7 +154,7 @@ impl<'a> AttrMethods for JSRef<'a, Attr> { // https://dom.spec.whatwg.org/#dom-attr-value fn Value(self) -> DOMString { - self.value().as_slice().to_owned() + (**self.value()).to_owned() } // https://dom.spec.whatwg.org/#dom-attr-value @@ -299,7 +302,7 @@ impl AttrHelpersForLayout for Attr { unsafe fn value_ref_forever(&self) -> &'static str { // This transmute is used to cheat the lifetime restriction. let value = mem::transmute::<&AttrValue, &AttrValue>(self.value.borrow_for_layout()); - value.as_slice() + &**value } #[inline] diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 4d895347251..eec797c23cd 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -377,7 +377,7 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); - value.as_slice() == fragid.as_slice() + &**value == &*fragid }) }; let doc_node: JSRef<Node> = NodeCast::from_ref(self); @@ -1324,7 +1324,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); - value.as_slice() == name.as_slice() + &**value == &*name }) }) } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index a9282d829b8..86c5ad25899 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1365,7 +1365,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { let doc = document_from_node(*self).root(); let base_url = doc.r().url(); let value = attr.value(); - let style = Some(parse_style_attribute(value.as_slice(), &base_url)); + let style = Some(parse_style_attribute(&value, &base_url)); *self.style_attribute.borrow_mut() = style; if node.is_in_doc() { @@ -1384,7 +1384,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { let value = attr.value(); if node.is_in_doc() { let doc = document_from_node(*self).root(); - if !value.as_slice().is_empty() { + if !value.is_empty() { let value = value.atom().unwrap().clone(); doc.r().register_named_element(*self, value); } @@ -1422,7 +1422,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> { let value = attr.value(); if node.is_in_doc() { let doc = document_from_node(*self).root(); - if !value.as_slice().is_empty() { + if !value.is_empty() { let value = value.atom().unwrap().clone(); doc.r().unregister_named_element(*self, value); } @@ -1496,8 +1496,8 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { // This transmute is used to cheat the lifetime restriction. // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); - let value = attr.value(); - unsafe { mem::transmute(value.as_slice()) } + let value: &str = &**attr.value(); + unsafe { mem::transmute(value) } }) } #[allow(unsafe_code)] @@ -1505,9 +1505,9 @@ impl<'a> style::node::TElement<'a> for JSRef<'a, Element> { self.get_attributes(local_name).into_iter().map(|attr| attr.root()).map(|attr| { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); - let value = attr.value(); + let value: &str = &**attr.value(); // This transmute is used to cheat the lifetime restriction. - unsafe { mem::transmute(value.as_slice()) } + unsafe { mem::transmute(value) } }).collect() } fn get_link(self) -> Option<&'a str> { diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs index 90ebdda550e..63156369459 100644 --- a/components/script/dom/htmlbodyelement.rs +++ b/components/script/dom/htmlbodyelement.rs @@ -108,12 +108,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLBodyElement> { }; evtarget.set_event_handler_uncompiled(cx, url, reflector, &name[2..], - attr.value().as_slice().to_owned()); + (**attr.value()).to_owned()); } match attr.local_name() { &atom!("bgcolor") => { - self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok()) + self.background_color.set(str::parse_legacy_color(&attr.value()).ok()) } _ => {} } diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs index 0a30989442b..d957648f959 100644 --- a/components/script/dom/htmlcanvaselement.rs +++ b/components/script/dom/htmlcanvaselement.rs @@ -226,11 +226,11 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLCanvasElement> { let value = attr.value(); let recreate = match attr.local_name() { &atom!("width") => { - self.width.set(parse_unsigned_integer(value.as_slice().chars()).unwrap_or(DEFAULT_WIDTH)); + self.width.set(parse_unsigned_integer(value.chars()).unwrap_or(DEFAULT_WIDTH)); true } &atom!("height") => { - self.height.set(parse_unsigned_integer(value.as_slice().chars()).unwrap_or(DEFAULT_HEIGHT)); + self.height.set(parse_unsigned_integer(value.chars()).unwrap_or(DEFAULT_HEIGHT)); true } _ => false, diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 68c097158dc..12f10e76c3a 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -203,7 +203,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for JSRef<'a, HTMLElement> { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); - value.as_slice().to_owned() + (**value).to_owned() }) } @@ -234,7 +234,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLElement> { let evtarget: JSRef<EventTarget> = EventTargetCast::from_ref(*self); evtarget.set_event_handler_uncompiled(cx, url, reflector, &name[2..], - attr.value().as_slice().to_owned()); + (**attr.value()).to_owned()); } } } diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 755e1168e40..08465fdf9aa 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -85,12 +85,12 @@ impl<'a> HTMLIFrameElementHelpers for JSRef<'a, HTMLIFrameElement> { let element: JSRef<Element> = ElementCast::from_ref(self); element.get_attribute(&ns!(""), &atom!("src")).root().and_then(|src| { let url = src.r().value(); - if url.as_slice().is_empty() { + if url.is_empty() { None } else { let window = window_from_node(self).root(); UrlParser::new().base_url(&window.r().get_url()) - .parse(url.as_slice()).ok() + .parse(&url).ok() } }) } diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 4ddf91cb8bd..b206ba44b38 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -284,7 +284,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> { &atom!("src") => { let window = window_from_node(*self).root(); let url = window.r().get_url(); - self.update_image(Some((attr.value().as_slice().to_owned(), &url))); + self.update_image(Some(((**attr.value()).to_owned(), &url))); }, _ => () } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 1f8abb17992..98272a1b8d4 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -479,7 +479,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { } &atom!("type") => { let value = attr.value(); - self.input_type.set(match value.as_slice() { + self.input_type.set(match &**value { "button" => InputType::InputButton, "submit" => InputType::InputSubmit, "reset" => InputType::InputReset, @@ -497,18 +497,18 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { } &atom!("value") => { if !self.value_changed.get() { - self.textinput.borrow_mut().set_content(attr.value().as_slice().to_owned()); + self.textinput.borrow_mut().set_content((**attr.value()).to_owned()); } } &atom!("name") => { if self.input_type.get() == InputType::InputRadio { let value = attr.value(); - self.radio_group_updated(Some(value.as_slice())); + self.radio_group_updated(Some(&value)); } } _ if attr.local_name() == &Atom::from_slice("placeholder") => { let value = attr.value(); - let stripped = value.as_slice().chars() + let stripped = value.chars() .filter(|&c| c != '\n' && c != '\r') .collect::<String>(); *self.placeholder.borrow_mut() = stripped; diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs index 82d8c33f919..d23fc5fc250 100644 --- a/components/script/dom/htmllinkelement.rs +++ b/components/script/dom/htmllinkelement.rs @@ -63,7 +63,7 @@ fn get_attr(element: JSRef<Element>, local_name: &Atom) -> Option<String> { // FIXME(https://github.com/rust-lang/rust/issues/23338) let e = e.r(); let value = e.value(); - value.as_slice().to_owned() + (**value).to_owned() }) } @@ -99,7 +99,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLLinkElement> { match (rel, attr.local_name()) { (ref rel, &atom!("href")) | (ref rel, &atom!("media")) => { if is_stylesheet(rel) { - self.handle_stylesheet_url(attr.value().as_slice()); + self.handle_stylesheet_url(&attr.value()); } } (_, _) => () diff --git a/components/script/dom/htmltablecellelement.rs b/components/script/dom/htmltablecellelement.rs index 22e44792f75..1737bddcb84 100644 --- a/components/script/dom/htmltablecellelement.rs +++ b/components/script/dom/htmltablecellelement.rs @@ -93,12 +93,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableCellElement> { match attr.local_name() { &atom!("bgcolor") => { - self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok()) + self.background_color.set(str::parse_legacy_color(&attr.value()).ok()) } &atom!("colspan") => { - self.colspan.set(str::parse_unsigned_integer(attr.value().as_slice().chars())); + self.colspan.set(str::parse_unsigned_integer(attr.value().chars())); } - &atom!("width") => self.width.set(str::parse_length(attr.value().as_slice())), + &atom!("width") => self.width.set(str::parse_length(&attr.value())), _ => () } } diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs index 437e5f6fa96..fe65327a585 100644 --- a/components/script/dom/htmltableelement.rs +++ b/components/script/dom/htmltableelement.rs @@ -130,18 +130,17 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableElement> { match attr.local_name() { &atom!("bgcolor") => { - self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok()) + self.background_color.set(str::parse_legacy_color(&attr.value()).ok()) } &atom!("border") => { // According to HTML5 § 14.3.9, invalid values map to 1px. self.border.set(Some(str::parse_unsigned_integer(attr.value() - .as_slice() .chars()).unwrap_or(1))) } &atom!("cellspacing") => { - self.cellspacing.set(str::parse_unsigned_integer(attr.value().as_slice().chars())) + self.cellspacing.set(str::parse_unsigned_integer(attr.value().chars())) } - &atom!("width") => self.width.set(str::parse_length(attr.value().as_slice())), + &atom!("width") => self.width.set(str::parse_length(&attr.value())), _ => () } } diff --git a/components/script/dom/htmltablerowelement.rs b/components/script/dom/htmltablerowelement.rs index 61497fa06fc..156dd6bb787 100644 --- a/components/script/dom/htmltablerowelement.rs +++ b/components/script/dom/htmltablerowelement.rs @@ -74,7 +74,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableRowElement> { match attr.local_name() { &atom!("bgcolor") => { - self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok()); + self.background_color.set(str::parse_legacy_color(&attr.value()).ok()); }, _ => () } diff --git a/components/script/dom/htmltablesectionelement.rs b/components/script/dom/htmltablesectionelement.rs index 1728bb6e8d2..27b26a79dd6 100644 --- a/components/script/dom/htmltablesectionelement.rs +++ b/components/script/dom/htmltablesectionelement.rs @@ -72,7 +72,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTableSectionElement> { match attr.local_name() { &atom!("bgcolor") => { - self.background_color.set(str::parse_legacy_color(attr.value().as_slice()).ok()); + self.background_color.set(str::parse_legacy_color(&attr.value()).ok()); }, _ => () } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index ca7d7598480..b8920f1adc0 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2254,7 +2254,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { other_element.attrs().iter().map(|attr| attr.root()).any(|other_attr| { (*attr.r().namespace() == *other_attr.r().namespace()) && (attr.r().local_name() == other_attr.r().local_name()) && - (attr.r().value().as_slice() == other_attr.r().value().as_slice()) + (**attr.r().value() == **other_attr.r().value()) }) }) } @@ -2520,7 +2520,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); - test(value.as_slice()) + test(&value) }) }, NamespaceConstraint::Any => { @@ -2530,7 +2530,7 @@ impl<'a> style::node::TNode<'a> for JSRef<'a, Node> { // FIXME(https://github.com/rust-lang/rust/issues/23338) let attr = attr.r(); let value = attr.value(); - test(value.as_slice()) + test(&value) }) } } diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index 73501809300..e67624441fe 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -215,7 +215,7 @@ impl<'a> Serializable for JSRef<'a, Node> { (qname, value) }).collect::<Vec<_>>(); let attr_refs = attrs.iter().map(|&(ref qname, ref value)| { - let ar: AttrRef = (&qname, value.as_slice()); + let ar: AttrRef = (&qname, &**value); ar }); try!(serializer.start_elem(name.clone(), attr_refs)); |