Auto merge of #9742 - nox:atom-from-string, r=ecoal95

Make use of From<String> for Atom

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9742)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-02-25 08:39:44 +05:30
commit b3b6f09206
36 changed files with 100 additions and 96 deletions

View file

@ -84,7 +84,7 @@ rustc-serialize = "0.3"
selectors = {version = "0.5", features = ["heap_size"]}
serde = "0.6"
smallvec = "0.1"
string_cache = {version = "0.2.9", features = ["heap_size", "unstable"]}
string_cache = {version = "0.2.10", features = ["heap_size", "unstable"]}
time = "0.1.12"
unicase = "1.0"
url = {version = "0.5.5", features = ["heap_size"]}

View file

@ -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)),
}
}

View file

@ -67,7 +67,7 @@ impl CloseEvent {
EventCancelable::NotCancelable
};
Ok(CloseEvent::new(global,
Atom::from(&*type_),
Atom::from(type_),
bubbles,
cancelable,
init.wasClean,

View file

@ -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) {

View file

@ -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

View file

@ -536,7 +536,7 @@ impl Document {
// Step 3 & 4
String::from_utf8(percent_decode(fragid.as_bytes())).ok()
// Step 5
.and_then(|decoded_fragid| self.get_element_by_id(&Atom::from(&*decoded_fragid)))
.and_then(|decoded_fragid| self.get_element_by_id(&Atom::from(decoded_fragid)))
// Step 6
.or_else(|| self.get_anchor_by_name(fragid))
// Step 7
@ -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,12 +1931,10 @@ impl DocumentMethods for Document {
if self.is_html_document {
local_name.make_ascii_lowercase();
}
let name = Atom::from(&*local_name);
// repetition used because string_cache::atom::Atom is non-copyable
let l_name = Atom::from(&*local_name);
let name = Atom::from(local_name);
let value = AttrValue::String(DOMString::new());
Ok(Attr::new(&self.window, name, value, l_name, ns!(), None, None))
Ok(Attr::new(&self.window, name.clone(), value, name, ns!(), None, None))
}
// https://dom.spec.whatwg.org/#dom-document-createattributens
@ -1947,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,
@ -2493,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.

View file

@ -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,

View file

@ -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 {
@ -925,7 +925,7 @@ impl Element {
None => qname.local.clone(),
Some(ref prefix) => {
let name = format!("{}:{}", &**prefix, &*qname.local);
Atom::from(&*name)
Atom::from(name)
},
};
let value = self.parse_attribute(&qname.ns, &qname.local, value);
@ -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);
}

View file

@ -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,

View file

@ -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

View file

@ -390,7 +390,7 @@ impl EventTarget {
b"colno\0" as *const u8 as *const c_char,
b"error\0" as *const u8 as *const c_char];
// step 10
let is_error = ty == &Atom::from("error") && self.is::<Window>();
let is_error = ty == &atom!("error") && self.is::<Window>();
let args = unsafe {
if is_error {
&ERROR_ARG_NAMES[..]
@ -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 {

View file

@ -59,7 +59,7 @@ impl FormDataMethods for FormData {
// https://xhr.spec.whatwg.org/#dom-formdata-append
fn Append(&self, name: USVString, value: USVString) {
let mut data = self.data.borrow_mut();
match data.entry(Atom::from(&*name.0)) {
match data.entry(Atom::from(name.0)) {
Occupied(entry) => entry.into_mut().push(FormDatum::StringData(value.0)),
Vacant (entry) => { entry.insert(vec!(FormDatum::StringData(value.0))); }
}
@ -70,7 +70,7 @@ impl FormDataMethods for FormData {
fn Append_(&self, name: USVString, value: &Blob, filename: Option<USVString>) {
let blob = FormDatum::BlobData(JS::from_rooted(&self.get_file_or_blob(value, filename)));
let mut data = self.data.borrow_mut();
match data.entry(Atom::from(&*name.0)) {
match data.entry(Atom::from(name.0)) {
Occupied(entry) => entry.into_mut().push(blob),
Vacant(entry) => {
entry.insert(vec!(blob));
@ -80,13 +80,13 @@ impl FormDataMethods for FormData {
// https://xhr.spec.whatwg.org/#dom-formdata-delete
fn Delete(&self, name: USVString) {
self.data.borrow_mut().remove(&Atom::from(&*name.0));
self.data.borrow_mut().remove(&Atom::from(name.0));
}
// https://xhr.spec.whatwg.org/#dom-formdata-get
fn Get(&self, name: USVString) -> Option<BlobOrUSVString> {
self.data.borrow()
.get(&Atom::from(&*name.0))
.get(&Atom::from(name.0))
.map(|entry| match entry[0] {
FormDatum::StringData(ref s) => BlobOrUSVString::USVString(USVString(s.clone())),
FormDatum::BlobData(ref b) => BlobOrUSVString::Blob(Root::from_ref(&*b)),
@ -96,7 +96,7 @@ impl FormDataMethods for FormData {
// https://xhr.spec.whatwg.org/#dom-formdata-getall
fn GetAll(&self, name: USVString) -> Vec<BlobOrUSVString> {
self.data.borrow()
.get(&Atom::from(&*name.0))
.get(&Atom::from(name.0))
.map_or(vec![], |data|
data.iter().map(|item| match *item {
FormDatum::StringData(ref s) => BlobOrUSVString::USVString(USVString(s.clone())),
@ -107,7 +107,7 @@ impl FormDataMethods for FormData {
// https://xhr.spec.whatwg.org/#dom-formdata-has
fn Has(&self, name: USVString) -> bool {
self.data.borrow().contains_key(&Atom::from(&*name.0))
self.data.borrow().contains_key(&Atom::from(name.0))
}
#[allow(unrooted_must_root)]
@ -117,7 +117,7 @@ impl FormDataMethods for FormData {
BlobOrUSVString::USVString(s) => FormDatum::StringData(s.0),
BlobOrUSVString::Blob(b) => FormDatum::BlobData(JS::from_rooted(&b))
};
self.data.borrow_mut().insert(Atom::from(&*name.0), vec!(val));
self.data.borrow_mut().insert(Atom::from(name.0), vec!(val));
}
}

View file

@ -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)

View file

@ -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);
}

View file

@ -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)

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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))