X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fxgccache.c;h=101e4fc49ea4cddfd979625817aef353807d5996;hb=8b6b965da075da197b3d654db3405aa6846bd3d8;hp=959251a0ab2adf602f076b8045b09f45d6e68b01;hpb=6883ee56ec887c2c48abe5b06b5e66aa74031910;p=chise%2Fxemacs-chise.git.1 diff --git a/src/xgccache.c b/src/xgccache.c index 959251a..101e4fc 100644 --- a/src/xgccache.c +++ b/src/xgccache.c @@ -43,7 +43,7 @@ Boston, MA 02111-1307, USA. */ used ones first). So if faces get changed, their GCs will eventually be recycled. Also more sharing of GCs is possible. - This code uses hashtables. It could be that, if the cache size is small + This code uses hash tables. It could be that, if the cache size is small enough, a linear search might be faster; but I doubt it, since we need `equal' comparisons, not `eq', and I expect that the optimal cache size will be ~100. @@ -84,7 +84,7 @@ struct gc_cache { struct gc_cache_cell *head; struct gc_cache_cell *tail; #ifdef GCCACHE_HASH - c_hashtable table; + struct hash_table *table; #endif int create_count; @@ -93,12 +93,12 @@ struct gc_cache { #ifdef GCCACHE_HASH static unsigned long -gc_cache_hash (CONST void *arg) +gc_cache_hash (const void *arg) { - CONST struct gcv_and_mask *gcvm = (CONST struct gcv_and_mask *) arg; + const struct gcv_and_mask *gcvm = (const struct gcv_and_mask *) arg; unsigned long *longs = (unsigned long *) &gcvm->gcv; unsigned long hash = gcvm->mask; - int i; + size_t i; /* This could look at the mask and only use the used slots in the hash code. That would win in that we wouldn't have to initialize every slot of the gcv when calling gc_cache_lookup. But we need @@ -112,7 +112,7 @@ gc_cache_hash (CONST void *arg) #endif /* GCCACHE_HASH */ static int -gc_cache_eql (CONST void *arg1, CONST void *arg2) +gc_cache_eql (const void *arg1, const void *arg2) { /* See comment in gc_cache_hash */ return !memcmp (arg1, arg2, sizeof (struct gcv_and_mask)); @@ -129,7 +129,7 @@ make_gc_cache (Display *dpy, Window window) cache->create_count = cache->delete_count = 0; #ifdef GCCACHE_HASH cache->table = - make_general_hashtable (GC_CACHE_SIZE, gc_cache_hash, gc_cache_eql); + make_general_hash_table (GC_CACHE_SIZE, gc_cache_hash, gc_cache_eql); #endif return cache; } @@ -147,7 +147,7 @@ free_gc_cache (struct gc_cache *cache) rest = next; } #ifdef GCCACHE_HASH - free_hashtable (cache->table); + free_hash_table (cache->table); #endif xfree (cache); } @@ -158,15 +158,15 @@ gc_cache_lookup (struct gc_cache *cache, XGCValues *gcv, unsigned long mask) struct gc_cache_cell *cell, *next, *prev; struct gcv_and_mask gcvm; - if ((!!cache->head) != (!!cache->tail)) abort (); - if (cache->head && (cache->head->prev || cache->tail->next)) abort (); + if ((!!cache->head) != (!!cache->tail)) ABORT (); + if (cache->head && (cache->head->prev || cache->tail->next)) ABORT (); gcvm.mask = mask; gcvm.gcv = *gcv; /* this copies... */ #ifdef GCCACHE_HASH - if (gethash (&gcvm, cache->table, (CONST void **) &cell)) + if (gethash (&gcvm, cache->table, (const void **) &cell)) #else /* !GCCACHE_HASH */ @@ -206,10 +206,10 @@ gc_cache_lookup (struct gc_cache *cache, XGCValues *gcv, unsigned long mask) cell->prev = cache->tail; cache->tail->next = cell; cache->tail = cell; - if (cache->head == cell) abort (); - if (cell->next) abort (); - if (cache->head->prev) abort (); - if (cache->tail->next) abort (); + if (cache->head == cell) ABORT (); + if (cell->next) ABORT (); + if (cache->head->prev) ABORT (); + if (cache->tail->next) ABORT (); return cell->gc; } @@ -231,7 +231,7 @@ gc_cache_lookup (struct gc_cache *cache, XGCValues *gcv, unsigned long mask) #endif } else if (cache->size > GC_CACHE_SIZE) - abort (); + ABORT (); else { /* Allocate a new cell (don't put it in the list or table yet). */ @@ -268,8 +268,6 @@ gc_cache_lookup (struct gc_cache *cache, XGCValues *gcv, unsigned long mask) #ifdef DEBUG_XEMACS -#include - void describe_gc_cache (struct gc_cache *cache); void describe_gc_cache (struct gc_cache *cache) @@ -290,32 +288,35 @@ describe_gc_cache (struct gc_cache *cache) gc_cache_hash (&cell->gcvm) == gc_cache_hash (&cell2->gcvm)) stderr_out ("\tHASH COLLISION with cell %d\n", i); stderr_out ("\tmask: %8lx\n", cell->gcvm.mask); -#define F(x) (int)cell->gcvm.gcv.x -#define G(w,x) if (F(x) != (~0)) stderr_out ("\t%-12s%8x\n", w, F(x)) - G("function:", function); - G("plane_mask:", plane_mask); - G("foreground:", foreground); - G("background:", background); - G("line_width:", line_width); - G("line_style:", line_style); - G("cap_style:", cap_style); - G("join_style:", join_style); - G("fill_style:", fill_style); - G("fill_rule:", fill_rule); - G("arc_mode:", arc_mode); - G("tile:", tile); - G("stipple:", stipple); - G("tsx_origin:", ts_x_origin); - G("tsy_origin:", ts_y_origin); - G("font:", font); - G("subwindow:", subwindow_mode); - G("gexposures:", graphics_exposures); - G("clip_x:", clip_x_origin); - G("clip_y:", clip_y_origin); - G("clip_mask:", clip_mask); - G("dash_off:", dash_offset); -#undef F -#undef G + +#define FROB(field) do { \ + if ((int)cell->gcvm.gcv.field != (~0)) \ + stderr_out ("\t%-12s%8x\n", #field ":", (int)cell->gcvm.gcv.field); \ +} while (0) + FROB (function); + FROB (plane_mask); + FROB (foreground); + FROB (background); + FROB (line_width); + FROB (line_style); + FROB (cap_style); + FROB (join_style); + FROB (fill_style); + FROB (fill_rule); + FROB (arc_mode); + FROB (tile); + FROB (stipple); + FROB (ts_x_origin); + FROB (ts_y_origin); + FROB (font); + FROB (subwindow_mode); + FROB (graphics_exposures); + FROB (clip_x_origin); + FROB (clip_y_origin); + FROB (clip_mask); + FROB (dash_offset); +#undef FROB + count++; if (cell->next && cell == cache->tail) stderr_out ("\nERROR! tail is here!\n\n");