mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
Cleanup Element::set_attribute.
This commit is contained in:
parent
33792db657
commit
58b317837b
2 changed files with 18 additions and 20 deletions
|
@ -9,8 +9,6 @@ use dom::window::Window;
|
||||||
use servo_util::namespace::{Namespace, Null};
|
use servo_util::namespace::{Namespace, Null};
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
|
||||||
use std::util;
|
|
||||||
|
|
||||||
#[deriving(Encodable)]
|
#[deriving(Encodable)]
|
||||||
pub struct Attr {
|
pub struct Attr {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
@ -63,9 +61,8 @@ impl Attr {
|
||||||
reflect_dom_object(~attr, window, AttrBinding::Wrap)
|
reflect_dom_object(~attr, window, AttrBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_value(&mut self, mut value: DOMString) -> DOMString {
|
pub fn set_value(&mut self, value: DOMString) {
|
||||||
util::swap(&mut self.value, &mut value);
|
self.value = value;
|
||||||
value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value_ref<'a>(&'a self) -> &'a str {
|
pub fn value_ref<'a>(&'a self) -> &'a str {
|
||||||
|
|
|
@ -204,22 +204,23 @@ impl Element {
|
||||||
self.node.wait_until_safe_to_modify_dom();
|
self.node.wait_until_safe_to_modify_dom();
|
||||||
|
|
||||||
// FIXME: reduce the time of `value.clone()`.
|
// FIXME: reduce the time of `value.clone()`.
|
||||||
let mut old_raw_value: Option<DOMString> = None;
|
let idx = self.attrs.iter().position(|attr| {
|
||||||
for attr in self.attrs.mut_iter() {
|
attr.get().local_name == local_name
|
||||||
let attr = attr.get_mut();
|
});
|
||||||
if attr.local_name == local_name {
|
let old_raw_value = idx.map(|idx| self.attrs[idx].get().Value());
|
||||||
old_raw_value = Some(attr.set_value(value.clone()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if old_raw_value.is_none() {
|
match idx {
|
||||||
let doc = self.node.owner_doc();
|
Some(idx) => {
|
||||||
let doc = doc.get();
|
self.attrs[idx].get_mut().set_value(value.clone());
|
||||||
let new_attr = Attr::new_ns(doc.window.get(), local_name.clone(), value.clone(),
|
}
|
||||||
name.clone(), namespace.clone(),
|
None => {
|
||||||
prefix);
|
let doc = self.node.owner_doc();
|
||||||
self.attrs.push(new_attr);
|
let doc = doc.get();
|
||||||
|
let new_attr = Attr::new_ns(doc.window.get(), local_name.clone(), value.clone(),
|
||||||
|
name.clone(), namespace.clone(),
|
||||||
|
prefix);
|
||||||
|
self.attrs.push(new_attr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if namespace == namespace::Null {
|
if namespace == namespace::Null {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue