summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-11-28 14:21:55 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-11-28 14:21:55 +0000
commitf6fb8c8a662e8403a579ceb548b8b51701ed58cf (patch)
tree8bb2979d092f0ac9c2b2799c70ee4fed804a60d1 /src
parent5aa8288b483e07769ae363d23c7cb27d9613a9d5 (diff)
downloadlibcss-f6fb8c8a662e8403a579ceb548b8b51701ed58cf.tar.gz
libcss-f6fb8c8a662e8403a579ceb548b8b51701ed58cf.tar.bz2
Optimise css_stylesheet_add_rule by the cunning approach of not iterating through a singly linked list to find the end every time we want to insert a rule. This doubles parsing speed.
svn path=/trunk/libcss/; revision=5811
Diffstat (limited to 'src')
-rw-r--r--src/stylesheet.c15
-rw-r--r--src/stylesheet.h1
2 files changed, 7 insertions, 9 deletions
diff --git a/src/stylesheet.c b/src/stylesheet.c
index ea3f2a6..0936243 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -759,8 +759,6 @@ css_error css_stylesheet_rule_append_style(css_stylesheet *sheet,
*/
css_error css_stylesheet_add_rule(css_stylesheet *sheet, css_rule *rule)
{
- css_rule *r;
-
if (sheet == NULL || rule == NULL)
return CSS_BADPARM;
@@ -771,16 +769,15 @@ css_error css_stylesheet_add_rule(css_stylesheet *sheet, css_rule *rule)
/* Add rule to sheet */
sheet->rule_count++;
- /** \todo this may need optimising */
- for (r = sheet->rule_list; r != NULL && r->next != NULL; r = r->next)
- /* do nothing */;
- if (r == NULL) {
+
+ if (sheet->last_rule == NULL) {
rule->prev = rule->next = NULL;
- sheet->rule_list = rule;
+ sheet->rule_list = sheet->last_rule = rule;
} else {
- r->next = rule;
- rule->prev = r;
+ sheet->last_rule->next = rule;
+ rule->prev = sheet->last_rule;
rule->next = NULL;
+ sheet->last_rule = rule;
}
/** \todo If there are selectors in the rule, add them to the hash
diff --git a/src/stylesheet.h b/src/stylesheet.h
index 2156b8e..a331299 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -142,6 +142,7 @@ struct css_stylesheet {
uint32_t rule_count; /**< Number of rules in sheet */
css_rule *rule_list; /**< List of rules in sheet */
+ css_rule *last_rule; /**< Last rule in list */
bool disabled; /**< Whether this sheet is
* disabled */