mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
script: Avoid an allocation when getting attribute data.
15% improvement in selector matching performance on the rainbow page.
This commit is contained in:
parent
192097315a
commit
1b786fe414
1 changed files with 4 additions and 3 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue