Skip to content

Commit

Permalink
script: Avoid an allocation when getting attribute data.
Browse files Browse the repository at this point in the history
15% improvement in selector matching performance on the rainbow page.
  • Loading branch information
pcwalton committed Jan 25, 2014
1 parent 1920973 commit 1b786fe
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/script/dom/element.rs
Expand Up @@ -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())
Expand Down

5 comments on commit 1b786fe

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from SimonSapin
at pcwalton@1b786fe

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pcwalton/servo/faster-attribute-comparison = 1b786fe into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pcwalton/servo/faster-attribute-comparison = 1b786fe merged ok, testing candidate = 86c29d2

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 86c29d2

Please sign in to comment.