aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-01-21 19:29:16 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-01-21 19:29:16 +0100
commit1fdebea2331ddd694af844adf6bf3d4ad6789928 (patch)
tree911e86796e990887893e568e13b8e698b8e77354
parentd8cfe548aa07ec4330d9760714a4312988135250 (diff)
refactor CssSelector::match() making it slightly more efficient
-rw-r--r--src/css.cc18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/css.cc b/src/css.cc
index 86c52c0f..49ef8945 100644
--- a/src/css.cc
+++ b/src/css.cc
@@ -67,22 +67,17 @@ CssSelector::~CssSelector () {
bool CssSelector::match (Doctree *docTree) {
CssSimpleSelector *sel;
- Combinator comb;
+ Combinator comb = CHILD;
int *notMatchingBefore;
const DoctreeNode *n, *node = docTree->top ();
assert (selectorList->size () > 0);
- sel = top ();
-
- if (! sel->match (node))
- return false;
+ for (int i = selectorList->size () - 1; i >= 0; i--) {
+ struct CombinatorAndSelector *cs = selectorList->getRef (i);
- for (int i = selectorList->size () - 2; i >= 0; i--) {
- sel = &selectorList->getRef (i)->selector;
- comb = selectorList->getRef (i + 1)->combinator;
- notMatchingBefore = &selectorList->getRef (i)->notMatchingBefore;
- node = docTree->parent (node);
+ sel = &cs->selector;
+ notMatchingBefore = &cs->notMatchingBefore;
if (node == NULL)
return false;
@@ -110,6 +105,9 @@ bool CssSelector::match (Doctree *docTree) {
default:
return false; // \todo implement other combinators
}
+
+ comb = cs->combinator;
+ node = docTree->parent (node);
}
return true;