summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-01-21 20:13:45 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-01-21 20:13:45 +0100
commit0bc40aa0f574f25f02c6a1ab4f0e399d41b75655 (patch)
treef476ee28e3cd11b022c65989eca24067829157af
parent9749792de478f44b82f3d4a5f47a740dd82e6421 (diff)
don't call docTree->top() over and over
-rw-r--r--src/css.cc28
-rw-r--r--src/css.hh8
2 files changed, 20 insertions, 16 deletions
diff --git a/src/css.cc b/src/css.cc
index f0364be5..4a110161 100644
--- a/src/css.cc
+++ b/src/css.cc
@@ -65,11 +65,11 @@ CssSelector::~CssSelector () {
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 @@ CssRule::~CssRule () {
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 @@ void CssStyleSheet::addRule (CssSelector *selector, CssPropertyList *props) {
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 @@ void CssStyleSheet::apply (CssPropertyList *props, Doctree *docTree) {
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 @@ CssContext::~CssContext () {
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);
diff --git a/src/css.hh b/src/css.hh
index 6b199833..122215f7 100644
--- a/src/css.hh
+++ b/src/css.hh
@@ -239,7 +239,7 @@ class CssSelector {
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 @@ class CssRule {
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 @@ class CssStyleSheet {
~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);
};
/**