1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:27:35 +00:00

LibWeb: Cache the result of Selector::specificity()

This function was showing up as taking 30% of all runtime during a
profile of Browser. This change effectively eliminates it completely.
This commit is contained in:
Idan Horowitz 2022-02-05 17:40:18 +02:00 committed by Andreas Kling
parent de7b5279cb
commit 89bd4cd80d
2 changed files with 7 additions and 1 deletions

View file

@ -20,6 +20,9 @@ Selector::~Selector()
u32 Selector::specificity() const
{
if (m_specificity.has_value())
return *m_specificity;
unsigned ids = 0;
unsigned tag_names = 0;
unsigned classes = 0;
@ -42,7 +45,9 @@ u32 Selector::specificity() const
}
}
return ids * 0x10000 + classes * 0x100 + tag_names;
m_specificity = ids * 0x10000 + classes * 0x100 + tag_names;
return *m_specificity;
}
// https://www.w3.org/TR/cssom/#serialize-a-simple-selector