From 79a34e5d5a9a93d9232efd595291bc5ebea2f2c5 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 30 Nov 2008 16:43:37 +0000 Subject: Use parserutils_hash instead of parserutils_dict. This approximately halves the size of the interned string table. We now have the following for allzengarden.css: 5507 slots used (of 8192 => 67.224121%) Data: 3 full blocks: 12288 bytes 10 partial blocks: 38946 bytes (of 40960 => 95.083008%) Total: 53488 (4112) (32) Entries: 21 full blocks: 86016 bytes 1 partial blocks: 2096 bytes (of 4096 => 51.171875%) Total: 90496 (4112) (32) Hash structures: 65592 Which gives a total dictionary size of 209,576 bytes. Note that 43% of this is parserutils_hash_entry structures (length-pointer pairs). It would be good, therefore, to be able to purge these. svn path=/trunk/libcss/; revision=5852 --- include/libcss/types.h | 6 +++--- src/parse/language.c | 2 +- src/parse/parse.c | 18 +++++++++--------- src/parse/parse.h | 4 ++-- src/stylesheet.c | 20 ++++++++++---------- src/stylesheet.h | 4 ++-- test/parse.c | 6 +++--- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/libcss/types.h b/include/libcss/types.h index 7bce679..8bda940 100644 --- a/include/libcss/types.h +++ b/include/libcss/types.h @@ -12,7 +12,7 @@ #include #include -#include +#include /** Source of charset information, in order of importance * A client-dictated charset will override all others. @@ -57,9 +57,9 @@ typedef enum css_origin { * String type * * \todo It might be better to define parserutils_string, and use that. - * (where parserutils_string is identical to parserutils_dict_entry) + * (where parserutils_string is identical to parserutils_hash_entry) */ -typedef parserutils_dict_entry css_string; +typedef parserutils_hash_entry css_string; typedef struct css_stylesheet css_stylesheet; diff --git a/src/parse/language.c b/src/parse/language.c index 4273658..d229c2a 100644 --- a/src/parse/language.c +++ b/src/parse/language.c @@ -409,7 +409,7 @@ css_error handleStartAtRule(css_language *c, const parserutils_vector *vector) return CSS_INVALID; } - entry.data = atkeyword->lower.data; + entry.data = (void *) atkeyword->lower.data; perror = parserutils_stack_push(c->context, (void *) &entry); if (perror != PARSERUTILS_OK) { diff --git a/src/parse/parse.c b/src/parse/parse.c index bfa6c27..d7ad461 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -91,7 +91,7 @@ struct css_parser #define STACK_CHUNK 32 parserutils_stack *states; /**< Stack of states */ - parserutils_dict *dictionary; /**< Dictionary for interned strings */ + parserutils_hash *dictionary; /**< Dictionary for interned strings */ parserutils_vector *tokens; /**< Vector of pending tokens */ @@ -185,7 +185,7 @@ static css_error (*parseFuncs[])(css_parser *parser) = { * CSS_NOMEM on memory exhaustion */ css_error css_parser_create(const char *charset, css_charset_source cs_source, - parserutils_dict *dictionary, css_alloc alloc, void *pw, + parserutils_hash *dictionary, css_alloc alloc, void *pw, css_parser **parser) { css_parser *p; @@ -420,13 +420,13 @@ const char *css_parser_read_charset(css_parser *parser, const uint8_t *css_parser_dict_add(css_parser *parser, const uint8_t *data, size_t len) { - const parserutils_dict_entry *interned; + const parserutils_hash_entry *interned; parserutils_error perror; if (parser == NULL || data == NULL || len == 0) return NULL; - perror = parserutils_dict_insert(parser->dictionary, data, len, + perror = parserutils_hash_insert(parser->dictionary, data, len, &interned); if (perror != PARSERUTILS_OK) return NULL; @@ -584,7 +584,7 @@ css_error getToken(css_parser *parser, const css_token **token) if (t->type != CSS_TOKEN_S && t->data.data != NULL && t->data.len > 0) { /* Insert token text into the dictionary */ - const parserutils_dict_entry *interned; + const parserutils_hash_entry *interned; uint8_t temp[t->data.len]; bool lower = false; @@ -607,7 +607,7 @@ css_error getToken(css_parser *parser, const css_token **token) /* We get to insert it twice - once for the raw * data, and once for a lowercased version that * we need internally. */ - perror = parserutils_dict_insert( + perror = parserutils_hash_insert( parser->dictionary, temp, t->data.len, &interned); @@ -619,13 +619,13 @@ css_error getToken(css_parser *parser, const css_token **token) t->lower.data = interned->data; t->lower.len = interned->len; - perror = parserutils_dict_insert( + perror = parserutils_hash_insert( parser->dictionary, t->data.data, t->data.len, &interned); } else { /* Otherwise, we're not interested in case */ - perror = parserutils_dict_insert( + perror = parserutils_hash_insert( parser->dictionary, t->data.data, t->data.len, &interned); diff --git a/src/parse/parse.h b/src/parse/parse.h index a948d56..7e57791 100644 --- a/src/parse/parse.h +++ b/src/parse/parse.h @@ -8,7 +8,7 @@ #ifndef css_parse_parse_h_ #define css_parse_parse_h_ -#include +#include #include #include @@ -57,7 +57,7 @@ typedef union css_parser_optparams { } css_parser_optparams; css_error css_parser_create(const char *charset, css_charset_source cs_source, - parserutils_dict *dict, css_alloc alloc, void *pw, + parserutils_hash *dict, css_alloc alloc, void *pw, css_parser **parser); css_error css_parser_destroy(css_parser *parser); diff --git a/src/stylesheet.c b/src/stylesheet.c index 5c6e68d..b2e1c0e 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -51,7 +51,7 @@ css_error css_stylesheet_create(css_language_level level, memset(sheet, 0, sizeof(css_stylesheet)); - perror = parserutils_dict_create((parserutils_alloc) alloc, alloc_pw, + perror = parserutils_hash_create((parserutils_alloc) alloc, alloc_pw, &sheet->dictionary); if (perror != PARSERUTILS_OK) { alloc(sheet, 0, alloc_pw); @@ -62,7 +62,7 @@ css_error css_stylesheet_create(css_language_level level, charset ? CSS_CHARSET_DICTATED : CSS_CHARSET_DEFAULT, sheet->dictionary, alloc, alloc_pw, &sheet->parser); if (error != CSS_OK) { - parserutils_dict_destroy(sheet->dictionary); + parserutils_hash_destroy(sheet->dictionary); alloc(sheet, 0, alloc_pw); return error; } @@ -72,7 +72,7 @@ css_error css_stylesheet_create(css_language_level level, &sheet->parser_frontend); if (error != CSS_OK) { css_parser_destroy(sheet->parser); - parserutils_dict_destroy(sheet->dictionary); + parserutils_hash_destroy(sheet->dictionary); alloc(sheet, 0, alloc_pw); return error; } @@ -84,7 +84,7 @@ css_error css_stylesheet_create(css_language_level level, if (sheet->url == NULL) { css_language_destroy(sheet->parser_frontend); css_parser_destroy(sheet->parser); - parserutils_dict_destroy(sheet->dictionary); + parserutils_hash_destroy(sheet->dictionary); alloc(sheet, 0, alloc_pw); return CSS_NOMEM; } @@ -97,7 +97,7 @@ css_error css_stylesheet_create(css_language_level level, alloc(sheet->url, 0, alloc_pw); css_language_destroy(sheet->parser_frontend); css_parser_destroy(sheet->parser); - parserutils_dict_destroy(sheet->dictionary); + parserutils_hash_destroy(sheet->dictionary); alloc(sheet, 0, alloc_pw); return CSS_NOMEM; } @@ -129,7 +129,7 @@ css_error css_stylesheet_destroy(css_stylesheet *sheet) if (sheet == NULL) return CSS_BADPARM; - parserutils_dict_destroy(sheet->dictionary); + parserutils_hash_destroy(sheet->dictionary); if (sheet->title != NULL) sheet->alloc(sheet->title, 0, sheet->pw); @@ -376,7 +376,7 @@ css_error css_stylesheet_selector_create(css_stylesheet *sheet, * the dictionary, it would be more efficient to pass a pointer to the * dictionary entry around rather than re-discovering it here. The same * applies for value, and in css_stylesheet_selector_detail_create() */ - perror = parserutils_dict_insert(sheet->dictionary, name->data, + perror = parserutils_hash_insert(sheet->dictionary, name->data, name->len, &iname); if (perror != PARSERUTILS_OK) { sheet->alloc(sel, 0, sheet->pw); @@ -385,7 +385,7 @@ css_error css_stylesheet_selector_create(css_stylesheet *sheet, sel->data.name = iname; if (value != NULL) { - perror = parserutils_dict_insert(sheet->dictionary, + perror = parserutils_hash_insert(sheet->dictionary, value->data, value->len, &ivalue); if (perror != PARSERUTILS_OK) { sheet->alloc(sel, 0, sheet->pw); @@ -454,7 +454,7 @@ css_error css_stylesheet_selector_detail_create(css_stylesheet *sheet, det->type = type; - perror = parserutils_dict_insert(sheet->dictionary, name->data, + perror = parserutils_hash_insert(sheet->dictionary, name->data, name->len, &iname); if (perror != PARSERUTILS_OK) { sheet->alloc(det, 0, sheet->pw); @@ -463,7 +463,7 @@ css_error css_stylesheet_selector_detail_create(css_stylesheet *sheet, det->name = iname; if (value != NULL) { - perror = parserutils_dict_insert(sheet->dictionary, + perror = parserutils_hash_insert(sheet->dictionary, value->data, value->len, &ivalue); if (perror != PARSERUTILS_OK) { sheet->alloc(det, 0, sheet->pw); diff --git a/src/stylesheet.h b/src/stylesheet.h index a331299..1ab3939 100644 --- a/src/stylesheet.h +++ b/src/stylesheet.h @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include @@ -169,7 +169,7 @@ struct css_stylesheet { css_parser *parser; /**< Core parser for sheet */ void *parser_frontend; /**< Frontend parser */ - parserutils_dict *dictionary; /**< String dictionary */ + parserutils_hash *dictionary; /**< String dictionary */ css_alloc alloc; /**< Allocation function */ void *pw; /**< Private word */ diff --git a/test/parse.c b/test/parse.c index 33dfe5f..fa0dae7 100644 --- a/test/parse.c +++ b/test/parse.c @@ -71,7 +71,7 @@ static css_error event_handler(css_parser_event type, int main(int argc, char **argv) { css_parser_optparams params; - parserutils_dict *dict; + parserutils_hash *dict; css_parser *parser; FILE *fp; size_t len, origlen; @@ -87,7 +87,7 @@ int main(int argc, char **argv) /* Initialise library */ assert(css_initialise(argv[1], myrealloc, NULL) == CSS_OK); - assert(parserutils_dict_create(myrealloc, NULL, &dict) == + assert(parserutils_hash_create(myrealloc, NULL, &dict) == PARSERUTILS_OK); assert(css_parser_create("UTF-8", CSS_CHARSET_DICTATED, dict, @@ -132,7 +132,7 @@ int main(int argc, char **argv) css_parser_destroy(parser); - parserutils_dict_destroy(dict); + parserutils_hash_destroy(dict); assert(css_finalise(myrealloc, NULL) == CSS_OK); -- cgit v1.2.3