diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-21 19:29:16 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-21 19:29:16 +0100 |
commit | 1fdebea2331ddd694af844adf6bf3d4ad6789928 (patch) | |
tree | 911e86796e990887893e568e13b8e698b8e77354 /src/css.cc | |
parent | d8cfe548aa07ec4330d9760714a4312988135250 (diff) |
refactor CssSelector::match() making it slightly more efficient
Diffstat (limited to 'src/css.cc')
-rw-r--r-- | src/css.cc | 18 |
1 files changed, 8 insertions, 10 deletions
@@ -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; |