script: Avoid an allocation when getting attribute data.

15% improvement in selector matching performance on the rainbow page.
This commit is contained in:
Patrick Walton 2014-01-24 16:57:26 -08:00
parent 192097315a
commit 1b786fe414

View file

@ -157,15 +157,16 @@ impl Element {
}).map(|&x| x)
}
#[inline]
pub unsafe fn get_attr_val_for_layout(&self, namespace: Namespace, name: &str)
-> Option<&'static str> {
// FIXME: only case-insensitive in the HTML namespace (as opposed to SVG, etc.)
let name = name.to_ascii_lower();
self.attrs.iter().find(|attr: & &@mut Attr| {
// unsafely avoid a borrow because this is accessed by many tasks
// during parallel layout
// FIXME: only case-insensitive in the HTML namespace (as opposed to SVG, etc.)
let attr: ***Box<Attr> = cast::transmute(attr);
name == (***attr).data.local_name && (***attr).data.namespace == namespace
name.eq_ignore_ascii_case((***attr).data.local_name) &&
(***attr).data.namespace == namespace
}).map(|attr| {
let attr: **Box<Attr> = cast::transmute(attr);
cast::transmute((**attr).data.value.as_slice())