style: Make DeclarationBlock::get O(1) if we know the longhand isn't there.

This commit is contained in:
Emilio Cobos Álvarez 2018-02-20 10:04:17 +01:00
parent df132b4954
commit f896cb63a6
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -292,8 +292,16 @@ impl PropertyDeclarationBlock {
/// 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)> {
if let PropertyDeclarationId::Longhand(id) = property {
if !self.contains(id) {
return None;
}
}
self.declarations.iter().enumerate().find(|&(_, decl)| decl.id() == property).map(|(i, decl)| {
let importance = if self.declarations_importance.get(i as u32) {
Importance::Important