From 35ab0a4e9406f9eeb29ca261680d911c423e4f90 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 11 Jun 2019 13:11:14 +0100 Subject: Media queries: Simplify parsed mq data structure slightly. --- src/parse/mq.c | 40 +++++++++++++--------------------------- src/parse/mq.h | 8 ++------ 2 files changed, 15 insertions(+), 33 deletions(-) (limited to 'src/parse') diff --git a/src/parse/mq.c b/src/parse/mq.c index 2e817d1..fb32b38 100644 --- a/src/parse/mq.c +++ b/src/parse/mq.c @@ -39,21 +39,13 @@ static void css__mq_feature_destroy(css_mq_feature *feature) static void css__mq_cond_or_feature_destroy( css_mq_cond_or_feature *cond_or_feature); -static void css__mq_cond_parts_destroy(css_mq_cond_parts *cond_parts) -{ - if (cond_parts != NULL) { - for (uint32_t i = 0; i < cond_parts->nparts; i++) { - css__mq_cond_or_feature_destroy(cond_parts->parts[i]); - } - free(cond_parts->parts); - free(cond_parts); - } -} - static void css__mq_cond_destroy(css_mq_cond *cond) { if (cond != NULL) { - css__mq_cond_parts_destroy(cond->parts); + for (uint32_t i = 0; i < cond->nparts; i++) { + css__mq_cond_or_feature_destroy(cond->parts[i]); + } + free(cond->parts); free(cond); } } @@ -790,12 +782,6 @@ static css_error mq_parse_condition(lwc_string **strings, return CSS_NOMEM; } memset(result, 0, sizeof(*result)); - result->parts = malloc(sizeof(*result->parts)); - if (result->parts == NULL) { - free(result); - return CSS_NOMEM; - } - memset(result->parts, 0, sizeof(*result->parts)); if (tokenIsChar(token, '(') == false) { /* Must be "not" */ @@ -810,14 +796,14 @@ static css_error mq_parse_condition(lwc_string **strings, } result->negate = 1; - result->parts->nparts = 1; - result->parts->parts = malloc(sizeof(*result->parts->parts)); - if (result->parts->parts == NULL) { + result->nparts = 1; + result->parts = malloc(sizeof(*result->parts)); + if (result->parts == NULL) { css__mq_cond_or_feature_destroy(cond_or_feature); css__mq_cond_destroy(result); return CSS_NOMEM; } - result->parts->parts[0] = cond_or_feature; + result->parts[0] = cond_or_feature; *cond = result; @@ -834,16 +820,16 @@ static css_error mq_parse_condition(lwc_string **strings, return CSS_INVALID; } - parts = realloc(result->parts->parts, - (result->parts->nparts+1)*sizeof(*result->parts->parts)); + parts = realloc(result->parts, + (result->nparts+1)*sizeof(*result->parts)); if (parts == NULL) { css__mq_cond_or_feature_destroy(cond_or_feature); css__mq_cond_destroy(result); return CSS_NOMEM; } - parts[result->parts->nparts] = cond_or_feature; - result->parts->parts = parts; - result->parts->nparts++; + parts[result->nparts] = cond_or_feature; + result->parts = parts; + result->nparts++; consumeWhitespace(vector, ctx); diff --git a/src/parse/mq.h b/src/parse/mq.h index 0e2f845..7a51578 100644 --- a/src/parse/mq.h +++ b/src/parse/mq.h @@ -56,15 +56,11 @@ typedef struct { typedef struct css_mq_cond_or_feature css_mq_cond_or_feature; -typedef struct { - uint32_t nparts; - css_mq_cond_or_feature **parts; -} css_mq_cond_parts; - typedef struct { uint32_t negate : 1, /* set if "not" */ op : 1; /* clear if "and", set if "or" */ - css_mq_cond_parts *parts; + uint32_t nparts; + css_mq_cond_or_feature **parts; } css_mq_cond; struct css_mq_cond_or_feature { -- cgit v1.2.3