Use DOMRefCell<T> in Attr.

This commit is contained in:
Tetsuharu OHZEKI 2014-10-15 03:33:25 +09:00
parent 80593d9cc5
commit 2d5d1e36ad

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::cell::{DOMRefCell, Ref};
use dom::bindings::codegen::Bindings::AttrBinding; use dom::bindings::codegen::Bindings::AttrBinding;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::codegen::InheritTypes::NodeCast;
@ -15,7 +16,6 @@ use dom::virtualmethods::vtable_for;
use devtools_traits::AttrInfo; use devtools_traits::AttrInfo;
use servo_util::str::{DOMString, split_html_space_chars}; use servo_util::str::{DOMString, split_html_space_chars};
use std::cell::{Ref, RefCell};
use std::mem; use std::mem;
use string_cache::{Atom, Namespace}; use string_cache::{Atom, Namespace};
@ -75,7 +75,7 @@ impl Str for AttrValue {
pub struct Attr { pub struct Attr {
reflector_: Reflector, reflector_: Reflector,
local_name: Atom, local_name: Atom,
value: RefCell<AttrValue>, value: DOMRefCell<AttrValue>,
name: Atom, name: Atom,
namespace: Namespace, namespace: Namespace,
prefix: Option<DOMString>, prefix: Option<DOMString>,
@ -97,7 +97,7 @@ impl Attr {
Attr { Attr {
reflector_: Reflector::new(), reflector_: Reflector::new(),
local_name: local_name, local_name: local_name,
value: RefCell::new(value), value: DOMRefCell::new(value),
name: name, name: name,
namespace: namespace, namespace: namespace,
prefix: prefix, prefix: prefix,
@ -221,15 +221,14 @@ pub trait AttrHelpersForLayout {
impl AttrHelpersForLayout for Attr { impl AttrHelpersForLayout for Attr {
#[inline] #[inline]
unsafe fn value_ref_forever(&self) -> &'static str { unsafe fn value_ref_forever(&self) -> &'static str {
// cast to point to T in RefCell<T> directly // This transmute is used to cheat the lifetime restriction.
let value = mem::transmute::<&RefCell<AttrValue>, &AttrValue>(&self.value); let value = mem::transmute::<&AttrValue, &AttrValue>(self.value.borrow_for_layout());
value.as_slice() value.as_slice()
} }
#[inline] #[inline]
unsafe fn value_atom_forever(&self) -> Option<Atom> { unsafe fn value_atom_forever(&self) -> Option<Atom> {
// cast to point to T in RefCell<T> directly let value = self.value.borrow_for_layout();
let value = mem::transmute::<&RefCell<AttrValue>, &AttrValue>(&self.value);
match *value { match *value {
AtomAttrValue(ref val) => Some(val.clone()), AtomAttrValue(ref val) => Some(val.clone()),
_ => None, _ => None,
@ -238,8 +237,8 @@ impl AttrHelpersForLayout for Attr {
#[inline] #[inline]
unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]> { unsafe fn value_tokens_forever(&self) -> Option<&'static [Atom]> {
// cast to point to T in RefCell<T> directly // This transmute is used to cheat the lifetime restriction.
let value = mem::transmute::<&RefCell<AttrValue>, &AttrValue>(&self.value); let value = mem::transmute::<&AttrValue, &AttrValue>(self.value.borrow_for_layout());
match *value { match *value {
TokenListAttrValue(_, ref tokens) => Some(tokens.as_slice()), TokenListAttrValue(_, ref tokens) => Some(tokens.as_slice()),
_ => None, _ => None,