mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Make DeclarationBlock::get O(1) if we know the longhand isn't there.
This commit is contained in:
parent
df132b4954
commit
f896cb63a6
1 changed files with 9 additions and 1 deletions
|
@ -292,8 +292,16 @@ impl PropertyDeclarationBlock {
|
||||||
|
|
||||||
/// Get a declaration for a given property.
|
/// Get a declaration for a given property.
|
||||||
///
|
///
|
||||||
/// NOTE: This is linear time.
|
/// NOTE: This is linear time in the case of custom properties or in the
|
||||||
|
/// case the longhand is actually in the declaration block.
|
||||||
|
#[inline]
|
||||||
pub fn get(&self, property: PropertyDeclarationId) -> Option<(&PropertyDeclaration, Importance)> {
|
pub fn get(&self, property: PropertyDeclarationId) -> Option<(&PropertyDeclaration, Importance)> {
|
||||||
|
if let PropertyDeclarationId::Longhand(id) = property {
|
||||||
|
if !self.contains(id) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.declarations.iter().enumerate().find(|&(_, decl)| decl.id() == property).map(|(i, decl)| {
|
self.declarations.iter().enumerate().find(|&(_, decl)| decl.id() == property).map(|(i, decl)| {
|
||||||
let importance = if self.declarations_importance.get(i as u32) {
|
let importance = if self.declarations_importance.get(i as u32) {
|
||||||
Importance::Important
|
Importance::Important
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue