summaryrefslogtreecommitdiff
path: root/test/select-auto.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-07-29 09:57:04 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-07-29 09:57:04 +0000
commit551c4e5bc7147f8eee1bb48cdd26bc83a66aa78a (patch)
treeaff3a1bb53332c80aa0b3e973c787baebaf3cc4a /test/select-auto.c
parentfc6b96707730c54fb7ac4040680d79864169b5e0 (diff)
downloadlibcss-551c4e5bc7147f8eee1bb48cdd26bc83a66aa78a.tar.gz
libcss-551c4e5bc7147f8eee1bb48cdd26bc83a66aa78a.tar.bz2
Change selector hash to segregate:
1) element selectors 2) universal selectors with class names 3) universal selectors with ids 4) universal selectors Only bother looking for matching selectors in 2 & 3 if the node being selected for has class names or an id, respectively. In theory, this should speed up style selection somewhat. svn path=/trunk/libcss/; revision=8882
Diffstat (limited to 'test/select-auto.c')
-rw-r--r--test/select-auto.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/select-auto.c b/test/select-auto.c
index 7e1ff35..2f3e028 100644
--- a/test/select-auto.c
+++ b/test/select-auto.c
@@ -72,6 +72,10 @@ static void destroy_tree(node *root);
static css_error node_name(void *pw, void *node, lwc_context *ctx,
lwc_string **name);
+static css_error node_classes(void *pw, void *node, lwc_context *ctx,
+ lwc_string ***classes, uint32_t *n_classes);
+static css_error node_id(void *pw, void *node, lwc_context *ctx,
+ lwc_string **id);
static css_error named_ancestor_node(void *pw, void *node,
lwc_string *name,
void **ancestor);
@@ -124,6 +128,8 @@ static css_error compute_font_size(void *pw, const css_hint *parent,
static css_select_handler select_handler = {
node_name,
+ node_classes,
+ node_id,
named_ancestor_node,
named_parent_node,
named_sibling_node,
@@ -721,6 +727,63 @@ css_error node_name(void *pw, void *n, lwc_context *ctx, lwc_string **name)
return CSS_OK;
}
+css_error node_classes(void *pw, void *n, lwc_context *ctx,
+ lwc_string ***classes, uint32_t *n_classes)
+{
+ node *node = n;
+ uint32_t i;
+ line_ctx *lc = pw;
+
+ for (i = 0; i < node->n_attrs; i++) {
+ bool amatch;
+ assert(lwc_context_string_caseless_isequal(ctx,
+ node->attrs[i].name, lc->attr_class, &amatch) ==
+ lwc_error_ok);
+ if (amatch == true)
+ break;
+ }
+
+ if (i != node->n_attrs) {
+ *classes = realloc(NULL, sizeof(lwc_string **));
+ if (*classes == NULL)
+ return CSS_NOMEM;
+
+ *(classes[0]) =
+ lwc_context_string_ref(ctx, node->attrs[i].value);
+ *n_classes = 1;
+ } else {
+ *classes = NULL;
+ *n_classes = 0;
+ }
+
+ return CSS_OK;
+
+}
+
+css_error node_id(void *pw, void *n, lwc_context *ctx,
+ lwc_string **id)
+{
+ node *node = n;
+ uint32_t i;
+ line_ctx *lc = pw;
+
+ for (i = 0; i < node->n_attrs; i++) {
+ bool amatch;
+ assert(lwc_context_string_caseless_isequal(ctx,
+ node->attrs[i].name, lc->attr_id, &amatch) ==
+ lwc_error_ok);
+ if (amatch == true)
+ break;
+ }
+
+ if (i != node->n_attrs)
+ *id = lwc_context_string_ref(ctx, node->attrs[i].value);
+ else
+ *id = NULL;
+
+ return CSS_OK;
+}
+
css_error named_ancestor_node(void *pw, void *n,
lwc_string *name,
void **ancestor)