summaryrefslogtreecommitdiff
path: root/src/select
diff options
context:
space:
mode:
Diffstat (limited to 'src/select')
-rw-r--r--src/select/select.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/select/select.c b/src/select/select.c
index b2820c8..411081e 100644
--- a/src/select/select.c
+++ b/src/select/select.c
@@ -496,6 +496,9 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
{
const css_stylesheet *s = sheet;
const css_rule *rule = s->rule_list;
+ uint32_t sp = 0;
+#define IMPORT_STACK_SIZE 256
+ const css_rule *import_stack[IMPORT_STACK_SIZE];
do {
/* Find first non-charset rule, if we're at the list head */
@@ -514,6 +517,10 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
if (import->sheet != NULL &&
(import->media & state->media) != 0) {
/* It's applicable, so process it */
+ assert(sp < IMPORT_STACK_SIZE - 1);
+
+ import_stack[sp++] = rule;
+
s = import->sheet;
rule = s->rule_list;
} else {
@@ -537,9 +544,10 @@ css_error select_from_sheet(css_select_ctx *ctx, const css_stylesheet *sheet,
return error;
/* Find next sheet to process */
- if (s->ownerRule != NULL) {
- rule = s->ownerRule->next;
- s = s->ownerRule->parent;
+ if (sp > 0) {
+ sp--;
+ rule = import_stack[sp]->next;
+ s = import_stack[sp]->parent;
} else {
s = NULL;
}