changeset 797:780557535771

refactor CssSelector::match() making it slightly more efficient
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Wed, 21 Jan 2009 19:29:16 +0100
parents 68f6aa2124ac
children 831ddf188e77
files src/css.cc
diffstat 1 files changed, 8 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Wed Jan 21 18:42:30 2009 +0100
+++ b/src/css.cc	Wed Jan 21 19:29:16 2009 +0100
@@ -67,22 +67,17 @@
 
 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 @@
          default:
             return false; // \todo implement other combinators
       }
+
+      comb = cs->combinator;
+      node = docTree->parent (node);
    } 
    
    return true;