mirror of
https://github.com/servo/servo.git
synced 2025-06-24 00:54:32 +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::str::DOMString;
|
||||
|
||||
use std::util;
|
||||
|
||||
#[deriving(Encodable)]
|
||||
pub struct Attr {
|
||||
reflector_: Reflector,
|
||||
|
@ -63,9 +61,8 @@ impl Attr {
|
|||
reflect_dom_object(~attr, window, AttrBinding::Wrap)
|
||||
}
|
||||
|
||||
pub fn set_value(&mut self, mut value: DOMString) -> DOMString {
|
||||
util::swap(&mut self.value, &mut value);
|
||||
value
|
||||
pub fn set_value(&mut self, value: DOMString) {
|
||||
self.value = value;
|
||||
}
|
||||
|
||||
pub fn value_ref<'a>(&'a self) -> &'a str {
|
||||
|
|
|
@ -204,22 +204,23 @@ impl Element {
|
|||
self.node.wait_until_safe_to_modify_dom();
|
||||
|
||||
// FIXME: reduce the time of `value.clone()`.
|
||||
let mut old_raw_value: Option<DOMString> = None;
|
||||
for attr in self.attrs.mut_iter() {
|
||||
let attr = attr.get_mut();
|
||||
if attr.local_name == local_name {
|
||||
old_raw_value = Some(attr.set_value(value.clone()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
let idx = self.attrs.iter().position(|attr| {
|
||||
attr.get().local_name == local_name
|
||||
});
|
||||
let old_raw_value = idx.map(|idx| self.attrs[idx].get().Value());
|
||||
|
||||
if old_raw_value.is_none() {
|
||||
let doc = self.node.owner_doc();
|
||||
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);
|
||||
match idx {
|
||||
Some(idx) => {
|
||||
self.attrs[idx].get_mut().set_value(value.clone());
|
||||
}
|
||||
None => {
|
||||
let doc = self.node.owner_doc();
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue