From 832b819d8bec7a517ee0ecccbf05beaccb1205fc Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 29 Aug 2022 11:53:11 +0100 Subject: Select: Move revert style tracking to separate allocation It's pretty big and the selection state lives on the stack. --- src/select/select.c | 24 +++++++++++++++++------- src/select/select.h | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/select/select.c b/src/select/select.c index e1f7883..f7dc098 100644 --- a/src/select/select.c +++ b/src/select/select.c @@ -1020,13 +1020,17 @@ static void css_select__finalise_selection_state( lwc_string_unref(state->element.name); } - for (size_t i = 0; i < CSS_ORIGIN_AUTHOR; i++) { - for (size_t j = 0; j < CSS_PSEUDO_ELEMENT_COUNT; j++) { - if (state->revert[i].style[j] == NULL) { - continue; + if (state->revert != NULL) { + for (size_t i = 0; i < CSS_ORIGIN_AUTHOR; i++) { + for (size_t j = 0; j < CSS_PSEUDO_ELEMENT_COUNT; j++) { + if (state->revert[i].style[j] == NULL) { + continue; + } + css_computed_style_destroy( + state->revert[i].style[j]); } - css_computed_style_destroy(state->revert[i].style[j]); } + free(state->revert); } } @@ -1284,8 +1288,14 @@ css_error css_select_style(css_select_ctx *ctx, void *node, printf("style:\t%s\tSELECTED\n", lwc_string_data(state.element.name)); #endif - /* Not sharing; need to select. - * Base element style is guaranteed to exist + /* Not sharing; need to select. */ + state.revert = calloc(CSS_ORIGIN_AUTHOR, sizeof(*state.revert)); + if (state.revert == NULL) { + error = CSS_NOMEM; + goto cleanup; + } + + /* Base element style is guaranteed to exist */ error = css__computed_style_create( &state.results->styles[CSS_PSEUDO_ELEMENT_NONE]); diff --git a/src/select/select.h b/src/select/select.h index 69bf4d8..5170e58 100644 --- a/src/select/select.h +++ b/src/select/select.h @@ -73,7 +73,7 @@ typedef struct css_select_state { css_select_results *results; /* Result set to populate */ /** UA and user styles for handling revert property value. */ - struct revert_data revert[CSS_ORIGIN_AUTHOR]; + struct revert_data *revert; /* Length: CSS_ORIGIN_AUTHOR */ css_pseudo_element current_pseudo; /* Current pseudo element */ css_computed_style *computed; /* Computed style to populate */ -- cgit v1.2.1