From dc00fb391c96b5ec3ad0bb70789465bca50f45ff Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 4 Nov 2011 22:50:50 +0000 Subject: Selection micro optimisation. svn path=/trunk/libcss/; revision=13120 --- src/select/select.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/select/select.c b/src/select/select.c index 1851f47..47aca20 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -1427,7 +1427,15 @@ css_error match_details(css_select_ctx *ctx, void *node, css_error error; css_pseudo_element pseudo = CSS_PSEUDO_ELEMENT_NONE; - /* We match by default (if there are no details than the element + /* Skip the element selector detail, which is always first. + * (Named elements are handled by match_named_combinator, so the + * element selector detail always matches here.) */ + if (detail->next) + detail++; + else + detail = NULL; + + /* We match by default (if there are no details other than the element * selector, then we must match) */ *match = true; @@ -1437,26 +1445,20 @@ css_error match_details(css_select_ctx *ctx, void *node, * simpler details come first (and thus the expensive match routines * can be avoided unless absolutely necessary)? */ - do { - /* Named elements are handled by match_named_combinator, so - * the element selector detail always matches here. */ - if (detail->type != CSS_SELECTOR_ELEMENT) { - - error = match_detail(ctx, node, detail, state, - match, &pseudo); - if (error != CSS_OK) - return error; + while (detail != NULL) { + error = match_detail(ctx, node, detail, state, match, &pseudo); + if (error != CSS_OK) + return error; - /* Detail doesn't match, so reject selector chain */ - if (*match == false) - return CSS_OK; - } + /* Detail doesn't match, so reject selector chain */ + if (*match == false) + return CSS_OK; if (detail->next) detail++; else detail = NULL; - } while (detail != NULL); + } /* Return the applicable pseudo element, if required */ if (pseudo_element != NULL) -- cgit v1.2.3