diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2012-02-03 15:29:20 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2012-02-03 15:29:20 +0100 |
commit | 1eb721680865658ed8ff04e13c81eb6a32b2b44c (patch) | |
tree | 2551cb051c80ce7731318c753ff92854e2571cf5 | |
parent | 27cc2be0735b9ff115a9565b905f3b46f26e9ec8 (diff) | |
download | mupdf-1eb721680865658ed8ff04e13c81eb6a32b2b44c.tar.xz |
Pass context explicitly to hash table functions.
-rw-r--r-- | draw/draw_glyph.c | 14 | ||||
-rw-r--r-- | fitz/base_hash.c | 40 | ||||
-rw-r--r-- | fitz/fitz.h | 18 | ||||
-rw-r--r-- | fitz/res_colorspace.c | 6 | ||||
-rw-r--r-- | fitz/res_store.c | 12 |
5 files changed, 44 insertions, 46 deletions
diff --git a/draw/draw_glyph.c b/draw/draw_glyph.c index 1edcef4a..d7704a57 100644 --- a/draw/draw_glyph.c +++ b/draw/draw_glyph.c @@ -49,19 +49,19 @@ fz_evict_glyph_cache(fz_context *ctx) fz_pixmap *pixmap; int i; - for (i = 0; i < fz_hash_len(cache->hash); i++) + for (i = 0; i < fz_hash_len(ctx, cache->hash); i++) { - key = fz_hash_get_key(cache->hash, i); + key = fz_hash_get_key(ctx, cache->hash, i); if (key->font) fz_drop_font(ctx, key->font); - pixmap = fz_hash_get_val(cache->hash, i); + pixmap = fz_hash_get_val(ctx, cache->hash, i); if (pixmap) fz_drop_pixmap(ctx, pixmap); } cache->total = 0; - fz_empty_hash(cache->hash); + fz_empty_hash(ctx, cache->hash); } void @@ -71,7 +71,7 @@ fz_free_glyph_cache_context(fz_context *ctx) return; fz_evict_glyph_cache(ctx); - fz_free_hash(ctx->glyph_cache->hash); + fz_free_hash(ctx, ctx->glyph_cache->hash); fz_free(ctx, ctx->glyph_cache); ctx->glyph_cache = NULL; } @@ -113,7 +113,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_color key.e = (ctm.e - floorf(ctm.e)) * 256; key.f = (ctm.f - floorf(ctm.f)) * 256; - val = fz_hash_find(cache->hash, &key); + val = fz_hash_find(ctx, cache->hash, &key); if (val) return fz_keep_pixmap(ctx, val); @@ -142,7 +142,7 @@ fz_render_glyph(fz_context *ctx, fz_font *font, int gid, fz_matrix ctm, fz_color fz_evict_glyph_cache(ctx); fz_try(ctx) { - fz_hash_insert(cache->hash, &key, val); + fz_hash_insert(ctx, cache->hash, &key, val); fz_keep_font(key.font); val = fz_keep_pixmap(ctx, val); } diff --git a/fitz/base_hash.c b/fitz/base_hash.c index 2cbd9f4b..b0a3b3f4 100644 --- a/fitz/base_hash.c +++ b/fitz/base_hash.c @@ -19,7 +19,6 @@ struct fz_hash_entry_s struct fz_hash_table_s { - fz_context *ctx; int keylen; int size; int load; @@ -50,7 +49,6 @@ fz_new_hash_table(fz_context *ctx, int initialsize, int keylen) assert(keylen <= MAX_KEY_LEN); table = fz_malloc_struct(ctx, fz_hash_table); - table->ctx = ctx; table->keylen = keylen; table->size = initialsize; table->load = 0; @@ -69,39 +67,39 @@ fz_new_hash_table(fz_context *ctx, int initialsize, int keylen) } void -fz_empty_hash(fz_hash_table *table) +fz_empty_hash(fz_context *ctx, fz_hash_table *table) { table->load = 0; memset(table->ents, 0, sizeof(fz_hash_entry) * table->size); } int -fz_hash_len(fz_hash_table *table) +fz_hash_len(fz_context *ctx, fz_hash_table *table) { return table->size; } void * -fz_hash_get_key(fz_hash_table *table, int idx) +fz_hash_get_key(fz_context *ctx, fz_hash_table *table, int idx) { return table->ents[idx].key; } void * -fz_hash_get_val(fz_hash_table *table, int idx) +fz_hash_get_val(fz_context *ctx, fz_hash_table *table, int idx) { return table->ents[idx].val; } void -fz_free_hash(fz_hash_table *table) +fz_free_hash(fz_context *ctx, fz_hash_table *table) { - fz_free(table->ctx, table->ents); - fz_free(table->ctx, table); + fz_free(ctx, table->ents); + fz_free(ctx, table); } static void -fz_resize_hash(fz_hash_table *table, int newsize) +fz_resize_hash(fz_context *ctx, fz_hash_table *table, int newsize) { fz_hash_entry *oldents = table->ents; int oldsize = table->size; @@ -110,11 +108,11 @@ fz_resize_hash(fz_hash_table *table, int newsize) if (newsize < oldload * 8 / 10) { - fz_warn(table->ctx, "assert: resize hash too small"); + fz_warn(ctx, "assert: resize hash too small"); return; } - table->ents = fz_malloc_array(table->ctx, newsize, sizeof(fz_hash_entry)); + table->ents = fz_malloc_array(ctx, newsize, sizeof(fz_hash_entry)); memset(table->ents, 0, sizeof(fz_hash_entry) * newsize); table->size = newsize; table->load = 0; @@ -123,15 +121,15 @@ fz_resize_hash(fz_hash_table *table, int newsize) { if (oldents[i].val) { - fz_hash_insert(table, oldents[i].key, oldents[i].val); + fz_hash_insert(ctx, table, oldents[i].key, oldents[i].val); } } - fz_free(table->ctx, oldents); + fz_free(ctx, oldents); } void * -fz_hash_find(fz_hash_table *table, void *key) +fz_hash_find(fz_context *ctx, fz_hash_table *table, void *key) { fz_hash_entry *ents = table->ents; unsigned size = table->size; @@ -150,7 +148,7 @@ fz_hash_find(fz_hash_table *table, void *key) } void -fz_hash_insert(fz_hash_table *table, void *key, void *val) +fz_hash_insert(fz_context *ctx, fz_hash_table *table, void *key, void *val) { fz_hash_entry *ents; unsigned size; @@ -158,7 +156,7 @@ fz_hash_insert(fz_hash_table *table, void *key, void *val) if (table->load > table->size * 8 / 10) { - fz_resize_hash(table, table->size * 2); + fz_resize_hash(ctx, table, table->size * 2); } ents = table->ents; @@ -176,14 +174,14 @@ fz_hash_insert(fz_hash_table *table, void *key, void *val) } if (memcmp(key, ents[pos].key, table->keylen) == 0) - fz_warn(table->ctx, "assert: overwrite hash slot"); + fz_warn(ctx, "assert: overwrite hash slot"); pos = (pos + 1) % size; } } void -fz_hash_remove(fz_hash_table *table, void *key) +fz_hash_remove(fz_context *ctx, fz_hash_table *table, void *key) { fz_hash_entry *ents = table->ents; unsigned size = table->size; @@ -194,7 +192,7 @@ fz_hash_remove(fz_hash_table *table, void *key) { if (!ents[pos].val) { - fz_warn(table->ctx, "assert: remove inexistent hash entry"); + fz_warn(ctx, "assert: remove inexistent hash entry"); return; } @@ -230,7 +228,7 @@ fz_hash_remove(fz_hash_table *table, void *key) } void -fz_debug_hash(fz_hash_table *table) +fz_debug_hash(fz_context *ctx, fz_hash_table *table) { int i, k; diff --git a/fitz/fitz.h b/fitz/fitz.h index a97817db..65fd47de 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -446,17 +446,17 @@ extern char *fz_optarg; typedef struct fz_hash_table_s fz_hash_table; fz_hash_table *fz_new_hash_table(fz_context *ctx, int initialsize, int keylen); -void fz_debug_hash(fz_hash_table *table); -void fz_empty_hash(fz_hash_table *table); -void fz_free_hash(fz_hash_table *table); +void fz_debug_hash(fz_context *ctx, fz_hash_table *table); +void fz_empty_hash(fz_context *ctx, fz_hash_table *table); +void fz_free_hash(fz_context *ctx, fz_hash_table *table); -void *fz_hash_find(fz_hash_table *table, void *key); -void fz_hash_insert(fz_hash_table *table, void *key, void *val); -void fz_hash_remove(fz_hash_table *table, void *key); +void *fz_hash_find(fz_context *ctx, fz_hash_table *table, void *key); +void fz_hash_insert(fz_context *ctx, fz_hash_table *table, void *key, void *val); +void fz_hash_remove(fz_context *ctx, fz_hash_table *table, void *key); -int fz_hash_len(fz_hash_table *table); -void *fz_hash_get_key(fz_hash_table *table, int idx); -void *fz_hash_get_val(fz_hash_table *table, int idx); +int fz_hash_len(fz_context *ctx, fz_hash_table *table); +void *fz_hash_get_key(fz_context *ctx, fz_hash_table *table, int idx); +void *fz_hash_get_val(fz_context *ctx, fz_hash_table *table, int idx); /* * Math and geometry diff --git a/fitz/res_colorspace.c b/fitz/res_colorspace.c index 1fdc8c4a..413da3ae 100644 --- a/fitz/res_colorspace.c +++ b/fitz/res_colorspace.c @@ -471,7 +471,7 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *src, fz_pixmap *dst) { for (x = 0; x < src->w; x++) { - color = fz_hash_find(lookup, s); + color = fz_hash_find(ctx, lookup, s); if (color) { memcpy(d, color, dstn); @@ -487,14 +487,14 @@ fz_std_conv_pixmap(fz_context *ctx, fz_pixmap *src, fz_pixmap *dst) for (k = 0; k < dstn; k++) *d++ = dstv[k] * 255; - fz_hash_insert(lookup, s - srcn, d - dstn); + fz_hash_insert(ctx, lookup, s - srcn, d - dstn); *d++ = *s++; } } } - fz_free_hash(lookup); + fz_free_hash(ctx, lookup); } } diff --git a/fitz/res_store.c b/fitz/res_store.c index 958df43e..398e8ece 100644 --- a/fitz/res_store.c +++ b/fitz/res_store.c @@ -118,7 +118,7 @@ evict(fz_context *ctx, fz_item *item) refkey.free = item->val->free; refkey.num = fz_to_num(item->key); refkey.gen = fz_to_gen(item->key); - fz_hash_remove(store->hash, &refkey); + fz_hash_remove(ctx, store->hash, &refkey); } /* Drop a reference to the value (freeing if required) */ if (item->val->refs > 0 && --item->val->refs == 0) @@ -220,7 +220,7 @@ fz_store_item(fz_context *ctx, fz_obj *key, void *val_, unsigned int itemsize) refkey.gen = fz_to_gen(key); fz_try(ctx) { - fz_hash_insert(store->hash, &refkey, item); + fz_hash_insert(ctx, store->hash, &refkey, item); } fz_catch(ctx) { @@ -263,7 +263,7 @@ fz_find_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key) refkey.free = free; refkey.num = fz_to_num(key); refkey.gen = fz_to_gen(key); - item = fz_hash_find(store->hash, &refkey); + item = fz_hash_find(ctx, store->hash, &refkey); } else { @@ -319,9 +319,9 @@ fz_remove_item(fz_context *ctx, fz_store_free_fn *free, fz_obj *key) refkey.free = free; refkey.num = fz_to_num(key); refkey.gen = fz_to_gen(key); - item = fz_hash_find(store->hash, &refkey); + item = fz_hash_find(ctx, store->hash, &refkey); if (item) - fz_hash_remove(store->hash, &refkey); + fz_hash_remove(ctx, store->hash, &refkey); } else { @@ -391,7 +391,7 @@ fz_free_store_context(fz_context *ctx) return; fz_empty_store(ctx); - fz_free_hash(ctx->store->hash); + fz_free_hash(ctx, ctx->store->hash); fz_free(ctx, ctx->store); ctx->store = NULL; } |