From a8b997e4e9ab6bae6f687def8568404c8aa4214b Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Tue, 8 Mar 2022 09:44:22 -0500 Subject: skinparser cleanup, optimize hash clause strings for =, ==, !=, <, > <=, >= store result of get_param() where possible Change-Id: Ia5a4dbf613d6ec9e21546fa0c6a8de28eb7aa347 --- apps/gui/skin_engine/skin_parser.c | 161 +++++++++++++++++++++++-------------- 1 file changed, 100 insertions(+), 61 deletions(-) diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index b3840f689f..7da772fab4 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -343,11 +343,12 @@ static int parse_image_display(struct skin_element *element, if (element->params_count > 1) { - if (get_param(element, 1)->type == CODE) + struct skin_tag_parameter *param1 = get_param(element, 1); + if (param1->type == CODE) id->token = get_param_code(element, 1)->data; /* specify a number. 1 being the first subimage (i.e top) NOT 0 */ - else if (get_param(element, 1)->type == INTEGER) - id->subimage = get_param(element, 1)->data.number - 1; + else if (param1->type == INTEGER) + id->subimage = param1->data.number - 1; if (element->params_count > 2) id->offset = get_param(element, 2)->data.number; } @@ -391,14 +392,16 @@ static int parse_image_load(struct skin_element *element, subimages = get_param(element, 2)->data.number; else if (element->params_count > 3) { - if (get_param(element, 2)->type == PERCENT) - x = get_param(element, 2)->data.number * curr_vp->vp.width / 1000; + struct skin_tag_parameter *param2 = get_param(element, 2); + struct skin_tag_parameter *param3 = get_param(element, 3); + if (param2->type == PERCENT) + x = param2->data.number * curr_vp->vp.width / 1000; else - x = get_param(element, 2)->data.number; - if (get_param(element, 3)->type == PERCENT) - y = get_param(element, 3)->data.number * curr_vp->vp.height / 1000; + x = param2->data.number; + if (param3->type == PERCENT) + y = param3->data.number * curr_vp->vp.height / 1000; else - y = get_param(element, 3)->data.number; + y = param3->data.number; if (element->params_count == 5) subimages = get_param(element, 4)->data.number; @@ -561,6 +564,7 @@ static int parse_listitemviewport(struct skin_element *element, struct wps_data *wps_data) { #ifndef __PCTOOL__ + struct skin_tag_parameter *param; struct listitem_viewport_cfg *cfg = skin_buffer_alloc(sizeof(*cfg)); if (!cfg) return -1; @@ -569,10 +573,15 @@ static int parse_listitemviewport(struct skin_element *element, cfg->label = PTRTOSKINOFFSET(skin_buffer, get_param_text(element, 0)); cfg->width = -1; cfg->height = -1; - if (!isdefault(get_param(element, 1))) - cfg->width = get_param(element, 1)->data.number; - if (!isdefault(get_param(element, 2))) - cfg->height = get_param(element, 2)->data.number; + + param = get_param(element, 1); + if (!isdefault(param)) + cfg->width = param->data.number; + + param = get_param(element, 2); + if (!isdefault(param)) + cfg->height = param->data.number; + if (element->params_count > 3 && !strcmp(get_param_text(element, 3), "tile")) cfg->tile = true; @@ -634,34 +643,39 @@ static int parse_drawrectangle( struct skin_element *element, struct wps_data *wps_data) { (void)wps_data; + struct skin_tag_parameter *param; struct draw_rectangle *rect = skin_buffer_alloc(sizeof(*rect)); if (!rect) return -1; - if (get_param(element, 0)->type == PERCENT) - rect->x = get_param(element, 0)->data.number * curr_vp->vp.width / 1000; + param = get_param(element, 0); + if (param->type == PERCENT) + rect->x = param->data.number * curr_vp->vp.width / 1000; else - rect->x = get_param(element, 0)->data.number; + rect->x = param->data.number; - if (get_param(element, 1)->type == PERCENT) - rect->y = get_param(element, 1)->data.number * curr_vp->vp.height / 1000; + param = get_param(element, 1); + if (param->type == PERCENT) + rect->y = param->data.number * curr_vp->vp.height / 1000; else - rect->y = get_param(element, 1)->data.number; + rect->y = param->data.number; - if (isdefault(get_param(element, 2))) + param = get_param(element, 2); + if (isdefault(param)) rect->width = curr_vp->vp.width - rect->x; - else if (get_param(element, 2)->type == PERCENT) - rect->width = get_param(element, 2)->data.number * curr_vp->vp.width / 1000; + else if (param->type == PERCENT) + rect->width = param->data.number * curr_vp->vp.width / 1000; else - rect->width = get_param(element, 2)->data.number; + rect->width = param->data.number; - if (isdefault(get_param(element, 3))) + param = get_param(element, 3); + if (isdefault(param)) rect->height = curr_vp->vp.height - rect->y; - else if (get_param(element, 3)->type == PERCENT) - rect->height = get_param(element, 3)->data.number * curr_vp->vp.height / 1000; + else if (param->type == PERCENT) + rect->height = param->data.number * curr_vp->vp.height / 1000; else - rect->height = get_param(element, 3)->data.number; + rect->height = param->data.number; rect->start_colour = curr_vp->vp.fg_pattern; rect->end_colour = curr_vp->vp.fg_pattern; @@ -811,19 +825,38 @@ static int parse_logical_if(struct skin_element *element, token->value.data = PTRTOSKINOFFSET(skin_buffer, lif); lif->token = get_param_code(element, 0)->data; - if (!strncmp(op, "=", 1)) - lif->op = IF_EQUALS; - else if (!strncmp(op, "!=", 2)) - lif->op = IF_NOTEQUALS; - else if (!strncmp(op, ">=", 2)) - lif->op = IF_GREATERTHAN_EQ; - else if (!strncmp(op, "<=", 2)) - lif->op = IF_LESSTHAN_EQ; - else if (!strncmp(op, ">", 2)) - lif->op = IF_GREATERTHAN; - else if (!strncmp(op, "<", 1)) - lif->op = IF_LESSTHAN; - + /* one or two operator conditionals */ + #define OPS2VAL(op1, op2) ((int)op1 << 8 | (int)op2) + #define CLAUSE(op1, op2, symbol) {OPS2VAL(op1, op2), symbol } + + struct clause_symbol {int value;int symbol;}; + static const struct clause_symbol get_clause_match[] = + { + CLAUSE('=', '=', IF_EQUALS), + CLAUSE('!', '=', IF_NOTEQUALS), + CLAUSE('>', '=', IF_GREATERTHAN_EQ), + CLAUSE('<', '=', IF_LESSTHAN_EQ), + /*All Single value items @ end */ + CLAUSE('>', 0, IF_GREATERTHAN), + CLAUSE('<', 0, IF_LESSTHAN), + CLAUSE('=', 0, IF_EQUALS), + }; + + int val1 = OPS2VAL(op[0], 0); + int val2; + if (val1 != 0) /* Empty string ?*/ + { + val2 = OPS2VAL(op[0], op[1]); + for (unsigned int i = 0; i < ARRAYLEN(get_clause_match); i++) + { + const struct clause_symbol *sym = &get_clause_match[i]; + if(sym->value == val1 || sym->value == val2) + { + lif->op = sym->symbol; + break; + } + } + } memcpy(&lif->operand, get_param(element, 2), sizeof(lif->operand)); if (element->params_count > 3) lif->num_options = get_param(element, 3)->data.number; @@ -1219,22 +1252,27 @@ static int parse_albumart_load(struct skin_element* element, aa->xalign = WPS_ALBUMART_ALIGN_CENTER; /* default */ aa->yalign = WPS_ALBUMART_ALIGN_CENTER; /* default */ - aa->x = get_param(element, 0)->data.number; - aa->y = get_param(element, 1)->data.number; - aa->width = get_param(element, 2)->data.number; - aa->height = get_param(element, 3)->data.number; + struct skin_tag_parameter *param0 = get_param(element, 0); + struct skin_tag_parameter *param1 = get_param(element, 1); + struct skin_tag_parameter *param2 = get_param(element, 2); + struct skin_tag_parameter *param3 = get_param(element, 3); + + aa->x = param0->data.number; + aa->y = param1->data.number; + aa->width = param2->data.number; + aa->height = param3->data.number; - if (!isdefault(get_param(element, 0)) && get_param(element, 0)->type == PERCENT) - aa->x = get_param(element, 0)->data.number * curr_vp->vp.width / 1000; + if (!isdefault(param0) && param0->type == PERCENT) + aa->x = param0->data.number * curr_vp->vp.width / 1000; - if (!isdefault(get_param(element, 1)) && get_param(element, 1)->type == PERCENT) - aa->y = get_param(element, 1)->data.number * curr_vp->vp.height / 1000; + if (!isdefault(param1) && param1->type == PERCENT) + aa->y = param1->data.number * curr_vp->vp.height / 1000; - if (!isdefault(get_param(element, 2)) && get_param(element, 2)->type == PERCENT) - aa->width = get_param(element, 2)->data.number * curr_vp->vp.width / 1000; + if (!isdefault(param2) && param2->type == PERCENT) + aa->width = param2->data.number * curr_vp->vp.width / 1000; - if (!isdefault(get_param(element, 3)) && get_param(element, 3)->type == PERCENT) - aa->height = get_param(element, 3)->data.number * curr_vp->vp.height / 1000; + if (!isdefault(param3) && param3->type == PERCENT) + aa->height = param3->data.number * curr_vp->vp.height / 1000; aa->vp = PTRTOSKINOFFSET(skin_buffer, &curr_vp->vp); aa->draw_handle = -1; @@ -1345,23 +1383,24 @@ static int parse_skinvar( struct skin_element *element, if (!data) return WPS_ERROR_INVALID_PARAM; data->var = PTRTOSKINOFFSET(skin_buffer, var); + char *text_param1 = get_param_text(element, 1); if (!isdefault(get_param(element, 2))) data->newval = get_param(element, 2)->data.number; - else if (strcmp(get_param_text(element, 1), "touch")) + else if (strcmp(text_param1, "touch")) return WPS_ERROR_INVALID_PARAM; data->max = 0; - if (!strcmp(get_param_text(element, 1), "set")) + if (!strcmp(text_param1, "set")) data->direct = true; - else if (!strcmp(get_param_text(element, 1), "inc")) + else if (!strcmp(text_param1, "inc")) { data->direct = false; } - else if (!strcmp(get_param_text(element, 1), "dec")) + else if (!strcmp(text_param1, "dec")) { data->direct = false; data->newval *= -1; } - else if (!strcmp(get_param_text(element, 1), "touch")) + else if (!strcmp(text_param1, "touch")) { data->direct = false; data->newval = 0; @@ -1403,12 +1442,12 @@ static int parse_lasttouch(struct skin_element *element, for (i=0; iparams_count; i++) { - if (get_param(element, i)->type == STRING) + struct skin_tag_parameter *param = get_param(element, i); + if (param->type == STRING) region = skin_find_item(get_param_text(element, i), SKIN_FIND_TOUCHREGION, wps_data); - else if (get_param(element, i)->type == INTEGER || - get_param(element, i)->type == DECIMAL) - data->timeout = get_param(element, i)->data.number; + else if (param->type == INTEGER || param->type == DECIMAL) + data->timeout = param->data.number; } data->region = PTRTOSKINOFFSET(skin_buffer, region); -- cgit v1.2.3