1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-05-18 00:48:57 -04:00

Move table cache stuff outside local renderer_context.

This commit is contained in:
Laurent MONIN 2005-10-20 17:17:25 +02:00 committed by Laurent MONIN
parent 23f7fc1b78
commit c17940044c

View File

@ -90,11 +90,11 @@ struct table_cache_entry {
#define MAX_TABLE_CACHE_ENTRIES 16384 #define MAX_TABLE_CACHE_ENTRIES 16384
/* Global variables */ /* Global variables */
static int table_cache_entries;
static struct hash *table_cache;
struct renderer_context { struct renderer_context {
int table_cache_entries;
struct hash *table_cache;
int last_link_to_move; int last_link_to_move;
struct tag *last_tag_to_move; struct tag *last_tag_to_move;
/* All tags between document->tags and this tag (inclusive) should /* All tags between document->tags and this tag (inclusive) should
@ -1750,20 +1750,20 @@ html_special(struct html_context *html_context, enum html_special_type c, ...)
void void
free_table_cache(void) free_table_cache(void)
{ {
if (renderer_context.table_cache) { if (table_cache) {
struct hash_item *item; struct hash_item *item;
int i; int i;
/* We do not free key here. */ /* We do not free key here. */
foreach_hash_item (item, *renderer_context.table_cache, i) { foreach_hash_item (item, *table_cache, i) {
mem_free_if(item->value); mem_free_if(item->value);
} }
free_hash(renderer_context.table_cache); free_hash(table_cache);
} }
renderer_context.table_cache = NULL; table_cache = NULL;
renderer_context.table_cache_entries = 0; table_cache_entries = 0;
} }
struct part * struct part *
@ -1783,8 +1783,8 @@ format_html_part(struct html_context *html_context,
struct table_cache_entry *tce; struct table_cache_entry *tce;
/* Hash creation if needed. */ /* Hash creation if needed. */
if (!renderer_context.table_cache) { if (!table_cache) {
renderer_context.table_cache = init_hash(8, &strhash); table_cache = init_hash(8, &strhash);
} else if (!document) { } else if (!document) {
/* Search for cached entry. */ /* Search for cached entry. */
struct table_cache_entry_key key; struct table_cache_entry_key key;
@ -1802,7 +1802,7 @@ format_html_part(struct html_context *html_context,
key.x = x; key.x = x;
key.link_num = link_num; key.link_num = link_num;
item = get_hash_item(renderer_context.table_cache, item = get_hash_item(table_cache,
(unsigned char *) &key, (unsigned char *) &key,
sizeof(key)); sizeof(key));
if (item) { /* We found it in cache, so just copy and return. */ if (item) { /* We found it in cache, so just copy and return. */
@ -1880,8 +1880,8 @@ ret:
renderer_context.empty_format = ef; renderer_context.empty_format = ef;
if (html_context->table_level > 1 && !document if (html_context->table_level > 1 && !document
&& renderer_context.table_cache && table_cache
&& renderer_context.table_cache_entries < MAX_TABLE_CACHE_ENTRIES) { && table_cache_entries < MAX_TABLE_CACHE_ENTRIES) {
/* Create a new entry. */ /* Create a new entry. */
/* Clear memory to prevent bad key comparaison due to alignment /* Clear memory to prevent bad key comparaison due to alignment
* of key fields. */ * of key fields. */
@ -1899,12 +1899,12 @@ ret:
tce->key.link_num = link_num; tce->key.link_num = link_num;
copy_struct(&tce->part, part); copy_struct(&tce->part, part);
if (!add_hash_item(renderer_context.table_cache, if (!add_hash_item(table_cache,
(unsigned char *) &tce->key, (unsigned char *) &tce->key,
sizeof(tce->key), tce)) { sizeof(tce->key), tce)) {
mem_free(tce); mem_free(tce);
} else { } else {
renderer_context.table_cache_entries++; table_cache_entries++;
} }
} }