Author: jmb
Date: Sun Nov 30 10:43:37 2008
New Revision: 5852
URL:
http://source.netsurf-browser.org?rev=5852&view=rev
Log:
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.
Modified:
trunk/libcss/include/libcss/types.h
trunk/libcss/src/parse/language.c
trunk/libcss/src/parse/parse.c
trunk/libcss/src/parse/parse.h
trunk/libcss/src/stylesheet.c
trunk/libcss/src/stylesheet.h
trunk/libcss/test/parse.c
Modified: trunk/libcss/include/libcss/types.h
URL:
http://source.netsurf-browser.org/trunk/libcss/include/libcss/types.h?rev...
==============================================================================
--- trunk/libcss/include/libcss/types.h (original)
+++ trunk/libcss/include/libcss/types.h Sun Nov 30 10:43:37 2008
@@ -12,7 +12,7 @@
#include <stdint.h>
#include <stdlib.h>
-#include <parserutils/utils/dict.h>
+#include <parserutils/utils/hash.h>
/** Source of charset information, in order of importance
* A client-dictated charset will override all others.
@@ -57,9 +57,9 @@
* 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;
Modified: trunk/libcss/src/parse/language.c
URL:
http://source.netsurf-browser.org/trunk/libcss/src/parse/language.c?rev=5...
==============================================================================
--- trunk/libcss/src/parse/language.c (original)
+++ trunk/libcss/src/parse/language.c Sun Nov 30 10:43:37 2008
@@ -409,7 +409,7 @@
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) {
Modified: trunk/libcss/src/parse/parse.c
URL:
http://source.netsurf-browser.org/trunk/libcss/src/parse/parse.c?rev=5852...
==============================================================================
--- trunk/libcss/src/parse/parse.c (original)
+++ trunk/libcss/src/parse/parse.c Sun Nov 30 10:43:37 2008
@@ -10,7 +10,7 @@
#include <stdbool.h>
#include <parserutils/input/inputstream.h>
-#include <parserutils/utils/dict.h>
+#include <parserutils/utils/hash.h>
#include <parserutils/utils/stack.h>
#include <parserutils/utils/vector.h>
@@ -91,7 +91,7 @@
#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 @@
* 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 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 @@
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 @@
/* 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 @@
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);
Modified: trunk/libcss/src/parse/parse.h
URL:
http://source.netsurf-browser.org/trunk/libcss/src/parse/parse.h?rev=5852...
==============================================================================
--- trunk/libcss/src/parse/parse.h (original)
+++ trunk/libcss/src/parse/parse.h Sun Nov 30 10:43:37 2008
@@ -8,7 +8,7 @@
#ifndef css_parse_parse_h_
#define css_parse_parse_h_
-#include <parserutils/utils/dict.h>
+#include <parserutils/utils/hash.h>
#include <parserutils/utils/vector.h>
#include <libcss/errors.h>
@@ -57,7 +57,7 @@
} 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);
Modified: trunk/libcss/src/stylesheet.c
URL:
http://source.netsurf-browser.org/trunk/libcss/src/stylesheet.c?rev=5852&...
==============================================================================
--- trunk/libcss/src/stylesheet.c (original)
+++ trunk/libcss/src/stylesheet.c Sun Nov 30 10:43:37 2008
@@ -51,7 +51,7 @@
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 @@
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 @@
&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 @@
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 @@
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 @@
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 @@
* 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 @@
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 @@
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 @@
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);
Modified: trunk/libcss/src/stylesheet.h
URL:
http://source.netsurf-browser.org/trunk/libcss/src/stylesheet.h?rev=5852&...
==============================================================================
--- trunk/libcss/src/stylesheet.h (original)
+++ trunk/libcss/src/stylesheet.h Sun Nov 30 10:43:37 2008
@@ -11,7 +11,7 @@
#include <inttypes.h>
#include <stdio.h>
-#include <parserutils/utils/dict.h>
+#include <parserutils/utils/hash.h>
#include <libcss/errors.h>
#include <libcss/functypes.h>
@@ -169,7 +169,7 @@
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 */
Modified: trunk/libcss/test/parse.c
URL:
http://source.netsurf-browser.org/trunk/libcss/test/parse.c?rev=5852&...
==============================================================================
--- trunk/libcss/test/parse.c (original)
+++ trunk/libcss/test/parse.c Sun Nov 30 10:43:37 2008
@@ -71,7 +71,7 @@
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 @@
/* 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 @@
css_parser_destroy(parser);
- parserutils_dict_destroy(dict);
+ parserutils_hash_destroy(dict);
assert(css_finalise(myrealloc, NULL) == CSS_OK);