changeset 799:9484cf6acee2

don't call docTree->top() over and over
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Wed, 21 Jan 2009 20:13:45 +0100
parents 831ddf188e77
children 756f3deec1b8
files src/css.cc src/css.hh
diffstat 2 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Wed Jan 21 19:34:25 2009 +0100
+++ b/src/css.cc	Wed Jan 21 20:13:45 2009 +0100
@@ -65,11 +65,11 @@
    delete selectorList;
 }
 
-bool CssSelector::match (Doctree *docTree) {
+bool CssSelector::match (Doctree *docTree, const DoctreeNode *node) {
    CssSimpleSelector *sel;
    Combinator comb = CHILD;
    int *notMatchingBefore;
-   const DoctreeNode *n, *node = docTree->top ();
+   const DoctreeNode *n;
 
    for (int i = selectorList->size () - 1; i >= 0; i--) {
       struct CombinatorAndSelector *cs = selectorList->getRef (i);
@@ -181,8 +181,9 @@
    props->unref ();
 };
 
-void CssRule::apply (CssPropertyList *props, Doctree *docTree) {
-   if (selector->match (docTree))
+void CssRule::apply (CssPropertyList *props,
+                     Doctree *docTree, const DoctreeNode *node) {
+   if (selector->match (docTree, node))
       this->props->apply (props);
 }
 
@@ -248,18 +249,18 @@
    addRule (rule);
 }
 
-void CssStyleSheet::apply (CssPropertyList *props, Doctree *docTree) {
+void CssStyleSheet::apply (CssPropertyList *props,
+                           Doctree *docTree, const DoctreeNode *node) {
    RuleList *ruleList[4] = {NULL, NULL, NULL, NULL};
-   const DoctreeNode *top = docTree->top ();
    
-   if (top->id) {
-      lout::object::String idString (top->id);
+   if (node->id) {
+      lout::object::String idString (node->id);
 
       ruleList[3] = idTable->get (&idString);
    }
 
-   if (top->klass) {
-      lout::object::String classString (top->klass);
+   if (node->klass) {
+      lout::object::String classString (node->klass);
 
       ruleList[2] = classTable->get (&classString);
    }
@@ -272,7 +273,7 @@
 
       for (int j = 0; j < 4; j++) {
          if (ruleList[j] && ruleList[j]->size () > i) {
-            ruleList[j]->get (i)->apply (props, docTree);
+            ruleList[j]->get (i)->apply (props, docTree, node);
             n++;
          }
       }
@@ -317,17 +318,18 @@
 
 void CssContext::apply (CssPropertyList *props, Doctree *docTree,
          CssPropertyList *tagStyle, CssPropertyList *nonCssHints) {
+   const DoctreeNode *node = docTree->top ();
 
    for (int o = CSS_PRIMARY_USER_AGENT; o <= CSS_PRIMARY_USER; o++)
       if (sheet[o])
-         sheet[o]->apply (props, docTree);
+         sheet[o]->apply (props, docTree, node);
 
    if (nonCssHints)
         nonCssHints->apply (props);
 
    for (int o = CSS_PRIMARY_AUTHOR; o <= CSS_PRIMARY_USER_IMPORTANT; o++)
       if (sheet[o])
-         sheet[o]->apply (props, docTree);
+         sheet[o]->apply (props, docTree, node);
 
    if (tagStyle)
         tagStyle->apply (props);
--- a/src/css.hh	Wed Jan 21 19:34:25 2009 +0100
+++ b/src/css.hh	Wed Jan 21 20:13:45 2009 +0100
@@ -239,7 +239,7 @@
          return &selectorList->getRef (selectorList->size () - 1)->selector;
       };
       inline int size () { return selectorList->size (); };
-      bool match (Doctree *dt);
+      bool match (Doctree *dt, const DoctreeNode *node);
       void print ();
       inline void ref () { refCount++; }
       inline void unref () { if(--refCount == 0) delete this; }
@@ -259,7 +259,8 @@
       CssRule (CssSelector *selector, CssPropertyList *props);
       ~CssRule ();
 
-      void apply (CssPropertyList *props, Doctree *docTree);
+      void apply (CssPropertyList *props,
+                  Doctree *docTree, const DoctreeNode *node);
       void print ();
 };
 
@@ -301,7 +302,8 @@
       ~CssStyleSheet();
       void addRule (CssRule *rule);
       void addRule (CssSelector *selector, CssPropertyList *props);
-      void apply (CssPropertyList *props, Doctree *docTree);
+      void apply (CssPropertyList *props,
+                  Doctree *docTree, const DoctreeNode *node);
 };
 
 /**