mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +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)
|
}).map(|&x| x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub unsafe fn get_attr_val_for_layout(&self, namespace: Namespace, name: &str)
|
pub unsafe fn get_attr_val_for_layout(&self, namespace: Namespace, name: &str)
|
||||||
-> Option<&'static 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| {
|
self.attrs.iter().find(|attr: & &@mut Attr| {
|
||||||
// unsafely avoid a borrow because this is accessed by many tasks
|
// unsafely avoid a borrow because this is accessed by many tasks
|
||||||
// during parallel layout
|
// during parallel layout
|
||||||
|
// FIXME: only case-insensitive in the HTML namespace (as opposed to SVG, etc.)
|
||||||
let attr: ***Box<Attr> = cast::transmute(attr);
|
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| {
|
}).map(|attr| {
|
||||||
let attr: **Box<Attr> = cast::transmute(attr);
|
let attr: **Box<Attr> = cast::transmute(attr);
|
||||||
cast::transmute((**attr).data.value.as_slice())
|
cast::transmute((**attr).data.value.as_slice())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue