Use or_init where appropriate.

This commit is contained in:
Ms2ger 2014-12-05 15:20:37 +01:00
parent 6bd9bf979b
commit f0ef1f97ad
5 changed files with 20 additions and 46 deletions

View file

@ -15,7 +15,7 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
use dom::bindings::codegen::InheritTypes::{ElementDerived, HTMLInputElementDerived};
use dom::bindings::codegen::InheritTypes::{HTMLTableCellElementDerived, NodeCast};
use dom::bindings::js::{MutNullableJS, JS, JSRef, Temporary, TemporaryPushable};
use dom::bindings::js::{OptionalSettable, OptionalRootable, Root};
use dom::bindings::js::{OptionalRootable, Root};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter, Syntax};
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
@ -708,25 +708,19 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
// http://dom.spec.whatwg.org/#dom-element-classlist
fn ClassList(self) -> Temporary<DOMTokenList> {
if self.class_list.get().is_none() {
let class_list = DOMTokenList::new(self, &atom!("class"));
self.class_list.assign(Some(class_list));
}
self.class_list.get().unwrap()
self.class_list.or_init(|| DOMTokenList::new(self, &atom!("class")))
}
// http://dom.spec.whatwg.org/#dom-element-attributes
fn Attributes(self) -> Temporary<NamedNodeMap> {
if self.attr_list.get().is_none() {
self.attr_list.or_init(|| {
let doc = {
let node: JSRef<Node> = NodeCast::from_ref(self);
node.owner_doc().root()
};
let window = doc.window().root();
let list = NamedNodeMap::new(*window, self);
self.attr_list.assign(Some(list));
}
self.attr_list.get().unwrap()
NamedNodeMap::new(*window, self)
})
}
// http://dom.spec.whatwg.org/#dom-element-getattribute