From a7229c649b98f1c5f5ea97c486b03dcc814c16ea Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 1 Dec 2008 15:24:24 +0000 Subject: Given that we're going to be copying selector details, anyway, it seems pointless to create objects on the heap which can equally well be on the stack, given the shortness of their lifetime. svn path=/trunk/libcss/; revision=5863 --- src/parse/language.c | 32 +++++++++++++------------------- src/stylesheet.c | 52 +++++++++++----------------------------------------- src/stylesheet.h | 6 ++---- 3 files changed, 26 insertions(+), 64 deletions(-) diff --git a/src/parse/language.c b/src/parse/language.c index 2bc5919..78b2045 100644 --- a/src/parse/language.c +++ b/src/parse/language.c @@ -74,13 +74,13 @@ static inline css_error handleDeclaration(css_language *c, /* Selector list parsing */ static inline css_error parseClass(css_language *c, const parserutils_vector *vector, int *ctx, - css_selector_detail **specific); + css_selector_detail *specific); static inline css_error parseAttrib(css_language *c, const parserutils_vector *vector, int *ctx, - css_selector_detail **specific); + css_selector_detail *specific); static inline css_error parsePseudo(css_language *c, const parserutils_vector *vector, int *ctx, - css_selector_detail **specific); + css_selector_detail *specific); static inline css_error parseSpecific(css_language *c, const parserutils_vector *vector, int *ctx, css_selector **parent); @@ -528,7 +528,7 @@ css_error handleDeclaration(css_language *c, const parserutils_vector *vector) ******************************************************************************/ css_error parseClass(css_language *c, const parserutils_vector *vector, - int *ctx, css_selector_detail **specific) + int *ctx, css_selector_detail *specific) { const css_token *token; @@ -541,12 +541,12 @@ css_error parseClass(css_language *c, const parserutils_vector *vector, if (token == NULL || token->type != CSS_TOKEN_IDENT) return CSS_INVALID; - return css_stylesheet_selector_detail_create(c->sheet, + return css_stylesheet_selector_detail_init(c->sheet, CSS_SELECTOR_CLASS, token->idata, NULL, specific); } css_error parseAttrib(css_language *c, const parserutils_vector *vector, - int *ctx, css_selector_detail **specific) + int *ctx, css_selector_detail *specific) { const css_token *token, *name, *value = NULL; css_selector_type type = CSS_SELECTOR_ATTRIBUTE; @@ -599,13 +599,13 @@ css_error parseAttrib(css_language *c, const parserutils_vector *vector, return CSS_INVALID; } - return css_stylesheet_selector_detail_create(c->sheet, type, + return css_stylesheet_selector_detail_init(c->sheet, type, name->idata, value != NULL ? value->idata : NULL, specific); } css_error parsePseudo(css_language *c, const parserutils_vector *vector, - int *ctx, css_selector_detail **specific) + int *ctx, css_selector_detail *specific) { const css_token *token, *name, *value = NULL; @@ -639,7 +639,7 @@ css_error parsePseudo(css_language *c, const parserutils_vector *vector, return CSS_INVALID; } - return css_stylesheet_selector_detail_create(c->sheet, + return css_stylesheet_selector_detail_init(c->sheet, CSS_SELECTOR_PSEUDO, name->idata, value != NULL ? value->idata : NULL, specific); } @@ -650,7 +650,7 @@ css_error parseSpecific(css_language *c, { css_error error; const css_token *token; - css_selector_detail *specific = NULL; + css_selector_detail specific; /* specific -> [ HASH | class | attrib | pseudo ] */ @@ -659,7 +659,7 @@ css_error parseSpecific(css_language *c, return CSS_INVALID; if (token->type == CSS_TOKEN_HASH) { - error = css_stylesheet_selector_detail_create(c->sheet, + error = css_stylesheet_selector_detail_init(c->sheet, CSS_SELECTOR_ID, token->idata, NULL, &specific); if (error != CSS_OK) return error; @@ -681,14 +681,8 @@ css_error parseSpecific(css_language *c, return CSS_INVALID; } - error = css_stylesheet_selector_append_specific(c->sheet, parent, - specific); - if (error != CSS_OK) { - css_stylesheet_selector_detail_destroy(c->sheet, specific); - return error; - } - - return CSS_OK; + return css_stylesheet_selector_append_specific(c->sheet, parent, + &specific); } css_error parseSelectorSpecifics(css_language *c, diff --git a/src/stylesheet.c b/src/stylesheet.c index ae254f7..72c5f02 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -402,71 +402,43 @@ css_error css_stylesheet_selector_destroy(css_stylesheet *sheet, } /** - * Create a selector detail + * Initialise a selector detail * * \param sheet The stylesheet context * \param type The type of selector to create * \param name Name of selector * \param value Value of selector, or NULL - * \param detail Pointer to location to receive detail object + * \param detail Pointer to detail object to initialise * \return CSS_OK on success, - * CSS_BADPARM on bad parameters, - * CSS_NOMEM on memory exhaustion + * CSS_BADPARM on bad parameters */ -css_error css_stylesheet_selector_detail_create(css_stylesheet *sheet, +css_error css_stylesheet_selector_detail_init(css_stylesheet *sheet, css_selector_type type, const parserutils_hash_entry *name, const parserutils_hash_entry *value, - css_selector_detail **detail) + css_selector_detail *detail) { - css_selector_detail *det; - if (sheet == NULL || name == NULL || detail == NULL) return CSS_BADPARM; - det = sheet->alloc(NULL, sizeof(css_selector_detail), sheet->pw); - if (det == NULL) - return CSS_NOMEM; - - memset(det, 0, sizeof(css_selector_detail)); - - det->type = type; - det->name = name; - det->value = value; - - *detail = det; - - return CSS_OK; -} - -/** - * Destroy a selector detail - * - * \param sheet The stylesheet context - * \param detail The detail to destroy - * \return CSS_OK on success, appropriate error otherwise - */ -css_error css_stylesheet_selector_detail_destroy(css_stylesheet *sheet, - css_selector_detail *detail) -{ - if (sheet == NULL || detail == NULL) - return CSS_BADPARM; + memset(detail, 0, sizeof(css_selector_detail)); - sheet->alloc(detail, 0, sheet->pw); + detail->type = type; + detail->name = name; + detail->value = value; return CSS_OK; } - /** * Append a selector to the specifics chain of another selector * * \param sheet The stylesheet context * \param parent Pointer to pointer to the parent selector (updated on exit) - * \param specific The selector to append (destroyed) + * \param specific The selector to append (copied) * \return CSS_OK on success, appropriate error otherwise. */ css_error css_stylesheet_selector_append_specific(css_stylesheet *sheet, - css_selector **parent, css_selector_detail *detail) + css_selector **parent, const css_selector_detail *detail) { css_selector *temp; css_selector_detail *d; @@ -496,8 +468,6 @@ css_error css_stylesheet_selector_append_specific(css_stylesheet *sheet, /* Flag that there's another block */ (&temp->data)[num_details].next = 1; - css_stylesheet_selector_detail_destroy(sheet, detail); - (*parent) = temp; return CSS_OK; diff --git a/src/stylesheet.h b/src/stylesheet.h index 9f9b21e..f32bbe3 100644 --- a/src/stylesheet.h +++ b/src/stylesheet.h @@ -185,15 +185,13 @@ css_error css_stylesheet_selector_create(css_stylesheet *sheet, css_error css_stylesheet_selector_destroy(css_stylesheet *sheet, css_selector *selector); -css_error css_stylesheet_selector_detail_create(css_stylesheet *sheet, +css_error css_stylesheet_selector_detail_init(css_stylesheet *sheet, css_selector_type type, const parserutils_hash_entry *name, const parserutils_hash_entry *value, - css_selector_detail **detail); -css_error css_stylesheet_selector_detail_destroy(css_stylesheet *sheet, css_selector_detail *detail); css_error css_stylesheet_selector_append_specific(css_stylesheet *sheet, - css_selector **parent, css_selector_detail *specific); + css_selector **parent, const css_selector_detail *specific); css_error css_stylesheet_selector_combine(css_stylesheet *sheet, css_combinator type, css_selector *a, css_selector *b); -- cgit v1.2.3