aboutsummaryrefslogtreecommitdiff
path: root/src/css.cc
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-12-16 21:48:25 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2008-12-16 21:48:25 +0100
commitf44234155a8f974fb00523ed62e9d16cfc72a2c6 (patch)
treec03c85ab0edaf1ad4cadcbd2561bd28f04fbb890 /src/css.cc
parent827a18d5e381c594871eb44468e7ca8976a446c4 (diff)
speed up CSS selector matching
A CssStyleSheet is now an array of lists of CssRules. The array holds a list if those rules that might potentially match whith a given element on the top of docTree.
Diffstat (limited to 'src/css.cc')
-rw-r--r--src/css.cc39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/css.cc b/src/css.cc
index 5b704a8a..9f7d827a 100644
--- a/src/css.cc
+++ b/src/css.cc
@@ -175,9 +175,34 @@ void CssRule::print () {
props->print ();
}
+CssStyleSheet::CssStyleSheet () {
+ for (int i = 0; i < ntags; i++)
+ ruleTable[i] = new lout::misc::SimpleVector <CssRule*> (1);
+}
+
+CssStyleSheet::~CssStyleSheet () {
+ for (int i = 0; i < ntags; i++) {
+ for (int j = 0; j < ruleTable[i]->size (); j++)
+ ruleTable[i]->get (j)->unref ();
+
+ delete ruleTable[i];
+ }
+}
+
void CssStyleSheet::addRule (CssRule *rule) {
- increase ();
- set (size () - 1, rule);
+ int topElement = rule->selector->top ()->element;
+
+ if (topElement == CssSimpleSelector::ELEMENT_ANY) {
+ for (int i = 0; i < ntags; i++) {
+ ruleTable[i]->increase ();
+ *ruleTable[i]->getRef (ruleTable[i]->size () - 1) = rule;
+ rule->ref ();
+ }
+ } else if (topElement >= 0 && topElement < ntags) {
+ ruleTable[topElement]->increase ();
+ *ruleTable[topElement]->getRef (ruleTable[topElement]->size () - 1) = rule;
+ rule->ref ();
+ }
}
void CssStyleSheet::addRule (CssSelector *selector, CssPropertyList *props) {
@@ -186,13 +211,11 @@ void CssStyleSheet::addRule (CssSelector *selector, CssPropertyList *props) {
}
void CssStyleSheet::apply (CssPropertyList *props, Doctree *docTree) {
- for (int i = 0; i < size (); i++)
- get (i)->apply (props, docTree);
-}
+ lout::misc::SimpleVector <CssRule*> *ruleList;
-CssStyleSheet::~CssStyleSheet () {
- for (int i = 0; i < size (); i++)
- delete get (i);
+ ruleList = ruleTable[docTree->top ()->element];
+ for (int i = 0; i < ruleList->size (); i++)
+ ruleList->get (i)->apply (props, docTree);
}
CssStyleSheet *CssContext::userAgentStyle;