aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-02-24 17:28:24 +0100
committerAnthony Ramine <n.oxyde@gmail.com>2016-02-24 17:52:17 +0100
commit0adfb080899104d4b51f6de3012ecf0558199b73 (patch)
tree60a23222f06c60f0f755158617d6256a23a1f5e2
parentf7fb03518836ba45b0883aaaf3b8d38a6ff5eae1 (diff)
downloadservo-0adfb080899104d4b51f6de3012ecf0558199b73.tar.gz
servo-0adfb080899104d4b51f6de3012ecf0558199b73.zip
Implement From<DOMString> for Atom
-rw-r--r--components/script/dom/bindings/xmlname.rs2
-rw-r--r--components/script/dom/closeevent.rs2
-rw-r--r--components/script/dom/cssstyledeclaration.rs4
-rw-r--r--components/script/dom/customevent.rs4
-rw-r--r--components/script/dom/document.rs14
-rw-r--r--components/script/dom/documentfragment.rs2
-rw-r--r--components/script/dom/element.rs10
-rw-r--r--components/script/dom/errorevent.rs2
-rw-r--r--components/script/dom/event.rs4
-rw-r--r--components/script/dom/eventtarget.rs4
-rw-r--r--components/script/dom/htmlcollection.rs6
-rw-r--r--components/script/dom/htmlelement.rs4
-rw-r--r--components/script/dom/messageevent.rs2
-rw-r--r--components/script/dom/namednodemap.rs4
-rw-r--r--components/script/dom/progressevent.rs2
-rw-r--r--components/script/dom/storageevent.rs2
-rw-r--r--components/script/dom/uievent.rs2
-rw-r--r--components/script/dom/webglcontextevent.rs2
-rw-r--r--components/style/attr.rs3
-rw-r--r--components/util/str.rs7
20 files changed, 44 insertions, 38 deletions
diff --git a/components/script/dom/bindings/xmlname.rs b/components/script/dom/bindings/xmlname.rs
index 6975fb8d702..b7dd7ca7d19 100644
--- a/components/script/dom/bindings/xmlname.rs
+++ b/components/script/dom/bindings/xmlname.rs
@@ -174,6 +174,6 @@ pub fn xml_name_type(name: &str) -> XMLName {
pub fn namespace_from_domstring(url: Option<DOMString>) -> Namespace {
match url {
None => ns!(),
- Some(s) => Namespace(Atom::from(&*s)),
+ Some(s) => Namespace(Atom::from(s)),
}
}
diff --git a/components/script/dom/closeevent.rs b/components/script/dom/closeevent.rs
index 44635462ad2..edf0c6199df 100644
--- a/components/script/dom/closeevent.rs
+++ b/components/script/dom/closeevent.rs
@@ -67,7 +67,7 @@ impl CloseEvent {
EventCancelable::NotCancelable
};
Ok(CloseEvent::new(global,
- Atom::from(&*type_),
+ Atom::from(type_),
bubbles,
cancelable,
init.wasClean,
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs
index f6683f9eae5..7c61098dc88 100644
--- a/components/script/dom/cssstyledeclaration.rs
+++ b/components/script/dom/cssstyledeclaration.rs
@@ -146,7 +146,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
// Step 1
property.make_ascii_lowercase();
- let property = Atom::from(&*property);
+ let property = Atom::from(property);
if self.readonly {
// Readonly style declarations are used for getComputedStyle.
@@ -185,7 +185,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
fn GetPropertyPriority(&self, mut property: DOMString) -> DOMString {
// Step 1
property.make_ascii_lowercase();
- let property = Atom::from(&*property);
+ let property = Atom::from(property);
// Step 2
if let Some(shorthand) = Shorthand::from_name(&property) {
diff --git a/components/script/dom/customevent.rs b/components/script/dom/customevent.rs
index f56e76ab7ff..3dd202d1aee 100644
--- a/components/script/dom/customevent.rs
+++ b/components/script/dom/customevent.rs
@@ -53,7 +53,7 @@ impl CustomEvent {
init: &CustomEventBinding::CustomEventInit)
-> Fallible<Root<CustomEvent>> {
Ok(CustomEvent::new(global,
- Atom::from(&*type_),
+ Atom::from(type_),
init.parent.bubbles,
init.parent.cancelable,
unsafe { HandleValue::from_marked_location(&init.detail) }))
@@ -87,7 +87,7 @@ impl CustomEventMethods for CustomEvent {
can_bubble: bool,
cancelable: bool,
detail: HandleValue) {
- self.init_custom_event(Atom::from(&*type_), can_bubble, cancelable, detail)
+ self.init_custom_event(Atom::from(type_), can_bubble, cancelable, detail)
}
// https://dom.spec.whatwg.org/#dom-event-istrusted
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 3ebd99518b1..b7c46c9666d 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -1847,7 +1847,7 @@ impl DocumentMethods for Document {
Vacant(entry) => {
let mut tag_copy = tag_name;
tag_copy.make_ascii_lowercase();
- let ascii_lower_tag = Atom::from(&*tag_copy);
+ let ascii_lower_tag = Atom::from(tag_copy);
let result = HTMLCollection::by_atomic_tag_name(&self.window,
self.upcast(),
tag_atom,
@@ -1864,7 +1864,7 @@ impl DocumentMethods for Document {
tag_name: DOMString)
-> Root<HTMLCollection> {
let ns = namespace_from_domstring(maybe_ns);
- let local = Atom::from(&*tag_name);
+ let local = Atom::from(tag_name);
let qname = QualName::new(ns, local);
match self.tagns_map.borrow_mut().entry(qname.clone()) {
Occupied(entry) => Root::from_ref(entry.get()),
@@ -1895,7 +1895,7 @@ impl DocumentMethods for Document {
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
fn GetElementById(&self, id: DOMString) -> Option<Root<Element>> {
- self.get_element_by_id(&Atom::from(&*id))
+ self.get_element_by_id(&Atom::from(id))
}
// https://dom.spec.whatwg.org/#dom-document-createelement
@@ -1907,7 +1907,7 @@ impl DocumentMethods for Document {
if self.is_html_document {
local_name.make_ascii_lowercase();
}
- let name = QualName::new(ns!(html), Atom::from(&*local_name));
+ let name = QualName::new(ns!(html), Atom::from(local_name));
Ok(Element::create(name, None, self, ElementCreator::ScriptCreated))
}
@@ -1931,7 +1931,7 @@ impl DocumentMethods for Document {
if self.is_html_document {
local_name.make_ascii_lowercase();
}
- let name = Atom::from(&*local_name);
+ let name = Atom::from(local_name);
let value = AttrValue::String(DOMString::new());
Ok(Attr::new(&self.window, name.clone(), value, name, ns!(), None, None))
@@ -1945,7 +1945,7 @@ impl DocumentMethods for Document {
let (namespace, prefix, local_name) = try!(validate_and_extract(namespace,
&qualified_name));
let value = AttrValue::String(DOMString::new());
- let qualified_name = Atom::from(&*qualified_name);
+ let qualified_name = Atom::from(qualified_name);
Ok(Attr::new(&self.window,
local_name,
value,
@@ -2491,7 +2491,7 @@ impl DocumentMethods for Document {
_ => false,
}
}
- let name = Atom::from(&*name);
+ let name = Atom::from(name);
let root = self.upcast::<Node>();
{
// Step 1.
diff --git a/components/script/dom/documentfragment.rs b/components/script/dom/documentfragment.rs
index 471da29be51..f77fb658d41 100644
--- a/components/script/dom/documentfragment.rs
+++ b/components/script/dom/documentfragment.rs
@@ -55,7 +55,7 @@ impl DocumentFragmentMethods for DocumentFragment {
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
fn GetElementById(&self, id: DOMString) -> Option<Root<Element>> {
let node = self.upcast::<Node>();
- let id = Atom::from(&*id);
+ let id = Atom::from(id);
node.traverse_preorder().filter_map(Root::downcast::<Element>).find(|descendant| {
match descendant.get_attribute(&ns!(), &atom!("id")) {
None => false,
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 3994ce20b0f..c1a60c3c2e5 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -617,7 +617,7 @@ impl Element {
if self.html_element_in_html_document() {
name.make_ascii_lowercase();
}
- Atom::from(&*name)
+ Atom::from(name)
}
pub fn namespace(&self) -> &Namespace {
@@ -952,7 +952,7 @@ impl Element {
}
// Steps 2-5.
- let name = Atom::from(&*name);
+ let name = Atom::from(name);
let value = self.parse_attribute(&ns!(), &name, value);
self.set_first_matching_attribute(name.clone(),
value,
@@ -1249,7 +1249,7 @@ impl ElementMethods for Element {
local_name: DOMString)
-> Option<Root<Attr>> {
let namespace = &namespace_from_domstring(namespace);
- self.get_attribute(namespace, &Atom::from(&*local_name))
+ self.get_attribute(namespace, &Atom::from(local_name))
}
// https://dom.spec.whatwg.org/#dom-element-setattribute
@@ -1277,7 +1277,7 @@ impl ElementMethods for Element {
value: DOMString) -> ErrorResult {
let (namespace, prefix, local_name) =
try!(validate_and_extract(namespace, &qualified_name));
- let qualified_name = Atom::from(&*qualified_name);
+ let qualified_name = Atom::from(qualified_name);
let value = self.parse_attribute(&namespace, &local_name, value);
self.set_first_matching_attribute(
local_name.clone(), value, qualified_name, namespace.clone(), prefix,
@@ -1344,7 +1344,7 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-removeattributens
fn RemoveAttributeNS(&self, namespace: Option<DOMString>, local_name: DOMString) {
let namespace = namespace_from_domstring(namespace);
- let local_name = Atom::from(&*local_name);
+ let local_name = Atom::from(local_name);
self.remove_attribute(&namespace, &local_name);
}
diff --git a/components/script/dom/errorevent.rs b/components/script/dom/errorevent.rs
index fd6c8d94e4a..c9d5a79b0fd 100644
--- a/components/script/dom/errorevent.rs
+++ b/components/script/dom/errorevent.rs
@@ -99,7 +99,7 @@ impl ErrorEvent {
// Dictionaries need to be rooted
// https://github.com/servo/servo/issues/6381
let error = RootedValue::new(global.get_cx(), init.error);
- let event = ErrorEvent::new(global, Atom::from(&*type_),
+ let event = ErrorEvent::new(global, Atom::from(type_),
bubbles, cancelable,
msg, file_name,
line_num, col_num,
diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs
index bae9dea1433..5aa97872647 100644
--- a/components/script/dom/event.rs
+++ b/components/script/dom/event.rs
@@ -96,7 +96,7 @@ impl Event {
init: &EventBinding::EventInit) -> Fallible<Root<Event>> {
let bubbles = if init.bubbles { EventBubbles::Bubbles } else { EventBubbles::DoesNotBubble };
let cancelable = if init.cancelable { EventCancelable::Cancelable } else { EventCancelable::NotCancelable };
- Ok(Event::new(global, Atom::from(&*type_), bubbles, cancelable))
+ Ok(Event::new(global, Atom::from(type_), bubbles, cancelable))
}
pub fn init_event(&self, type_: Atom, bubbles: bool, cancelable: bool) {
@@ -240,7 +240,7 @@ impl EventMethods for Event {
type_: DOMString,
bubbles: bool,
cancelable: bool) {
- self.init_event(Atom::from(&*type_), bubbles, cancelable)
+ self.init_event(Atom::from(type_), bubbles, cancelable)
}
// https://dom.spec.whatwg.org/#dom-event-istrusted
diff --git a/components/script/dom/eventtarget.rs b/components/script/dom/eventtarget.rs
index e3beb2a5b09..36aae8800da 100644
--- a/components/script/dom/eventtarget.rs
+++ b/components/script/dom/eventtarget.rs
@@ -494,7 +494,7 @@ impl EventTargetMethods for EventTarget {
capture: bool) {
if let Some(listener) = listener {
let mut handlers = self.handlers.borrow_mut();
- let entry = match handlers.entry(Atom::from(&*ty)) {
+ let entry = match handlers.entry(Atom::from(ty)) {
Occupied(entry) => entry.into_mut(),
Vacant(entry) => entry.insert(EventListeners(vec!())),
};
@@ -517,7 +517,7 @@ impl EventTargetMethods for EventTarget {
capture: bool) {
if let Some(ref listener) = listener {
let mut handlers = self.handlers.borrow_mut();
- let entry = handlers.get_mut(&Atom::from(&*ty));
+ let entry = handlers.get_mut(&Atom::from(ty));
for entry in entry {
let phase = if capture { ListenerPhase::Capturing } else { ListenerPhase::Bubbling };
let old_entry = EventListenerEntry {
diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs
index b2c691fb762..d36fb177e7b 100644
--- a/components/script/dom/htmlcollection.rs
+++ b/components/script/dom/htmlcollection.rs
@@ -115,9 +115,9 @@ impl HTMLCollection {
pub fn by_tag_name(window: &Window, root: &Node, mut tag: DOMString)
-> Root<HTMLCollection> {
- let tag_atom = Atom::from(&*tag); // FIXME(ajeffrey): Convert directly from DOMString to Atom
+ let tag_atom = Atom::from(&*tag);
tag.make_ascii_lowercase();
- let ascii_lower_tag = Atom::from(&*tag); // FIXME(ajeffrey): Convert directly from DOMString to Atom
+ let ascii_lower_tag = Atom::from(tag); // FIXME(ajeffrey): don't clone atom if it was already lowercased.
HTMLCollection::by_atomic_tag_name(window, root, tag_atom, ascii_lower_tag)
}
@@ -148,7 +148,7 @@ impl HTMLCollection {
pub fn by_tag_name_ns(window: &Window, root: &Node, tag: DOMString,
maybe_ns: Option<DOMString>) -> Root<HTMLCollection> {
- let local = Atom::from(&*tag); // FIXME(ajeffrey): Convert directly from DOMString to Atom
+ let local = Atom::from(tag);
let ns = namespace_from_domstring(maybe_ns);
let qname = QualName::new(ns, local);
HTMLCollection::by_qual_tag_name(window, root, qname)
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index 9ed0f1f6494..70e370a8c8a 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -340,7 +340,7 @@ impl HTMLElement {
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
// FIXME(ajeffrey): Convert directly from DOMString to Atom
- let local_name = Atom::from(&*to_snake_case(local_name));
+ let local_name = Atom::from(to_snake_case(local_name));
self.upcast::<Element>().get_attribute(&ns!(), &local_name).map(|attr| {
DOMString::from(&**attr.value()) // FIXME(ajeffrey): Convert directly from AttrValue to DOMString
})
@@ -348,7 +348,7 @@ impl HTMLElement {
pub fn delete_custom_attr(&self, local_name: DOMString) {
// FIXME(ajeffrey): Convert directly from DOMString to Atom
- let local_name = Atom::from(&*to_snake_case(local_name));
+ let local_name = Atom::from(to_snake_case(local_name));
self.upcast::<Element>().remove_attribute(&ns!(), &local_name);
}
diff --git a/components/script/dom/messageevent.rs b/components/script/dom/messageevent.rs
index f68f37a872a..3f4571ff528 100644
--- a/components/script/dom/messageevent.rs
+++ b/components/script/dom/messageevent.rs
@@ -67,7 +67,7 @@ impl MessageEvent {
// Dictionaries need to be rooted
// https://github.com/servo/servo/issues/6381
let data = RootedValue::new(global.get_cx(), init.data);
- let ev = MessageEvent::new(global, Atom::from(&*type_), init.parent.bubbles, init.parent.cancelable,
+ let ev = MessageEvent::new(global, Atom::from(type_), init.parent.bubbles, init.parent.cancelable,
data.handle(),
init.origin.clone(), init.lastEventId.clone());
Ok(ev)
diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs
index ca564f04e00..94e21b65bf6 100644
--- a/components/script/dom/namednodemap.rs
+++ b/components/script/dom/namednodemap.rs
@@ -56,7 +56,7 @@ impl NamedNodeMapMethods for NamedNodeMap {
fn GetNamedItemNS(&self, namespace: Option<DOMString>, local_name: DOMString)
-> Option<Root<Attr>> {
let ns = namespace_from_domstring(namespace);
- self.owner.get_attribute(&ns, &Atom::from(&*local_name))
+ self.owner.get_attribute(&ns, &Atom::from(local_name))
}
// https://dom.spec.whatwg.org/#dom-namednodemap-setnameditem
@@ -79,7 +79,7 @@ impl NamedNodeMapMethods for NamedNodeMap {
fn RemoveNamedItemNS(&self, namespace: Option<DOMString>, local_name: DOMString)
-> Fallible<Root<Attr>> {
let ns = namespace_from_domstring(namespace);
- self.owner.remove_attribute(&ns, &Atom::from(&*local_name))
+ self.owner.remove_attribute(&ns, &Atom::from(local_name))
.ok_or(Error::NotFound)
}
diff --git a/components/script/dom/progressevent.rs b/components/script/dom/progressevent.rs
index 985cc289d61..e7b0b1510ef 100644
--- a/components/script/dom/progressevent.rs
+++ b/components/script/dom/progressevent.rs
@@ -50,7 +50,7 @@ impl ProgressEvent {
let bubbles = if init.parent.bubbles { EventBubbles::Bubbles } else { EventBubbles::DoesNotBubble };
let cancelable = if init.parent.cancelable { EventCancelable::Cancelable }
else { EventCancelable::NotCancelable };
- let ev = ProgressEvent::new(global, Atom::from(&*type_), bubbles, cancelable,
+ let ev = ProgressEvent::new(global, Atom::from(type_), bubbles, cancelable,
init.lengthComputable, init.loaded, init.total);
Ok(ev)
}
diff --git a/components/script/dom/storageevent.rs b/components/script/dom/storageevent.rs
index 215054a6e38..4c7200f5fc1 100644
--- a/components/script/dom/storageevent.rs
+++ b/components/script/dom/storageevent.rs
@@ -76,7 +76,7 @@ impl StorageEvent {
} else {
EventCancelable::NotCancelable
};
- let event = StorageEvent::new(global, Atom::from(&*type_),
+ let event = StorageEvent::new(global, Atom::from(type_),
bubbles, cancelable,
key, oldValue, newValue,
url, storageArea);
diff --git a/components/script/dom/uievent.rs b/components/script/dom/uievent.rs
index 1c4ba4b5fb8..bc340638255 100644
--- a/components/script/dom/uievent.rs
+++ b/components/script/dom/uievent.rs
@@ -92,7 +92,7 @@ impl UIEventMethods for UIEvent {
return;
}
- event.init_event(Atom::from(&*type_), can_bubble, cancelable);
+ event.init_event(Atom::from(type_), can_bubble, cancelable);
self.view.set(view);
self.detail.set(detail);
}
diff --git a/components/script/dom/webglcontextevent.rs b/components/script/dom/webglcontextevent.rs
index 71ab79a34db..195848273fe 100644
--- a/components/script/dom/webglcontextevent.rs
+++ b/components/script/dom/webglcontextevent.rs
@@ -79,7 +79,7 @@ impl WebGLContextEvent {
EventCancelable::NotCancelable
};
- Ok(WebGLContextEvent::new(global, Atom::from(&*type_),
+ Ok(WebGLContextEvent::new(global, Atom::from(type_),
bubbles,
cancelable,
status_message))
diff --git a/components/style/attr.rs b/components/style/attr.rs
index 7c85975ee83..76918f0c410 100644
--- a/components/style/attr.rs
+++ b/components/style/attr.rs
@@ -129,8 +129,7 @@ impl AttrValue {
}
pub fn from_atomic(string: DOMString) -> AttrValue {
- // FIXME(ajeffrey): convert directly from DOMString to Atom
- let value = Atom::from(&*string);
+ let value = Atom::from(string);
AttrValue::Atom(value)
}
diff --git a/components/util/str.rs b/components/util/str.rs
index 2ffde43fedf..9d0869ccced 100644
--- a/components/util/str.rs
+++ b/components/util/str.rs
@@ -11,6 +11,7 @@ use std::fmt;
use std::iter::{Filter, Peekable};
use std::ops::{Deref, DerefMut};
use std::str::{Bytes, CharIndices, FromStr, Split, from_utf8};
+use string_cache::Atom;
#[derive(Clone, Debug, Deserialize, Eq, Hash, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
pub struct DOMString(String);
@@ -96,6 +97,12 @@ impl<'a> From<&'a str> for DOMString {
}
}
+impl From<DOMString> for Atom {
+ fn from(contents: DOMString) -> Atom {
+ Atom::from(contents.0)
+ }
+}
+
impl From<DOMString> for String {
fn from(contents: DOMString) -> String {
contents.0