Mercurial > hg > xemacs-beta
comparison src/xgccache.c @ 380:8626e4521993 r21-2-5
Import from CVS: tag r21-2-5
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:07:10 +0200 |
parents | 558f606b08ae |
children | 74fd4e045ea6 |
comparison
equal
deleted
inserted
replaced
379:76b7d63099ad | 380:8626e4521993 |
---|---|
41 level. There is an upper limit on the size of the cache, after which we | 41 level. There is an upper limit on the size of the cache, after which we |
42 will stop creating GCs and start reusing them (reusing the least-recently- | 42 will stop creating GCs and start reusing them (reusing the least-recently- |
43 used ones first). So if faces get changed, their GCs will eventually be | 43 used ones first). So if faces get changed, their GCs will eventually be |
44 recycled. Also more sharing of GCs is possible. | 44 recycled. Also more sharing of GCs is possible. |
45 | 45 |
46 This code uses hashtables. It could be that, if the cache size is small | 46 This code uses hash tables. It could be that, if the cache size is small |
47 enough, a linear search might be faster; but I doubt it, since we need | 47 enough, a linear search might be faster; but I doubt it, since we need |
48 `equal' comparisons, not `eq', and I expect that the optimal cache size | 48 `equal' comparisons, not `eq', and I expect that the optimal cache size |
49 will be ~100. | 49 will be ~100. |
50 | 50 |
51 Written by jwz, 14 jun 93 | 51 Written by jwz, 14 jun 93 |
82 Window window; /* used only as arg to XCreateGC */ | 82 Window window; /* used only as arg to XCreateGC */ |
83 int size; | 83 int size; |
84 struct gc_cache_cell *head; | 84 struct gc_cache_cell *head; |
85 struct gc_cache_cell *tail; | 85 struct gc_cache_cell *tail; |
86 #ifdef GCCACHE_HASH | 86 #ifdef GCCACHE_HASH |
87 c_hashtable table; | 87 struct hash_table *table; |
88 #endif | 88 #endif |
89 | 89 |
90 int create_count; | 90 int create_count; |
91 int delete_count; | 91 int delete_count; |
92 }; | 92 }; |
127 cache->size = 0; | 127 cache->size = 0; |
128 cache->head = cache->tail = 0; | 128 cache->head = cache->tail = 0; |
129 cache->create_count = cache->delete_count = 0; | 129 cache->create_count = cache->delete_count = 0; |
130 #ifdef GCCACHE_HASH | 130 #ifdef GCCACHE_HASH |
131 cache->table = | 131 cache->table = |
132 make_general_hashtable (GC_CACHE_SIZE, gc_cache_hash, gc_cache_eql); | 132 make_general_hash_table (GC_CACHE_SIZE, gc_cache_hash, gc_cache_eql); |
133 #endif | 133 #endif |
134 return cache; | 134 return cache; |
135 } | 135 } |
136 | 136 |
137 void | 137 void |
145 next = rest->next; | 145 next = rest->next; |
146 xfree (rest); | 146 xfree (rest); |
147 rest = next; | 147 rest = next; |
148 } | 148 } |
149 #ifdef GCCACHE_HASH | 149 #ifdef GCCACHE_HASH |
150 free_hashtable (cache->table); | 150 free_hash_table (cache->table); |
151 #endif | 151 #endif |
152 xfree (cache); | 152 xfree (cache); |
153 } | 153 } |
154 | 154 |
155 GC | 155 GC |
265 return cell->gc; | 265 return cell->gc; |
266 } | 266 } |
267 | 267 |
268 | 268 |
269 #ifdef DEBUG_XEMACS | 269 #ifdef DEBUG_XEMACS |
270 | |
271 #include <stdio.h> | |
272 | 270 |
273 void describe_gc_cache (struct gc_cache *cache); | 271 void describe_gc_cache (struct gc_cache *cache); |
274 void | 272 void |
275 describe_gc_cache (struct gc_cache *cache) | 273 describe_gc_cache (struct gc_cache *cache) |
276 { | 274 { |
288 for (cell2 = cache->head; cell2; cell2 = cell2->next, i++) | 286 for (cell2 = cache->head; cell2; cell2 = cell2->next, i++) |
289 if (count != i && | 287 if (count != i && |
290 gc_cache_hash (&cell->gcvm) == gc_cache_hash (&cell2->gcvm)) | 288 gc_cache_hash (&cell->gcvm) == gc_cache_hash (&cell2->gcvm)) |
291 stderr_out ("\tHASH COLLISION with cell %d\n", i); | 289 stderr_out ("\tHASH COLLISION with cell %d\n", i); |
292 stderr_out ("\tmask: %8lx\n", cell->gcvm.mask); | 290 stderr_out ("\tmask: %8lx\n", cell->gcvm.mask); |
293 #define F(x) (int)cell->gcvm.gcv.x | 291 |
294 #define G(w,x) if (F(x) != (~0)) stderr_out ("\t%-12s%8x\n", w, F(x)) | 292 #define FROB(field) do { \ |
295 G("function:", function); | 293 if ((int)cell->gcvm.gcv.field != (~0)) \ |
296 G("plane_mask:", plane_mask); | 294 stderr_out ("\t%-12s%8x\n", #field ":", (int)cell->gcvm.gcv.field); \ |
297 G("foreground:", foreground); | 295 } while (0) |
298 G("background:", background); | 296 FROB (function); |
299 G("line_width:", line_width); | 297 FROB (plane_mask); |
300 G("line_style:", line_style); | 298 FROB (foreground); |
301 G("cap_style:", cap_style); | 299 FROB (background); |
302 G("join_style:", join_style); | 300 FROB (line_width); |
303 G("fill_style:", fill_style); | 301 FROB (line_style); |
304 G("fill_rule:", fill_rule); | 302 FROB (cap_style); |
305 G("arc_mode:", arc_mode); | 303 FROB (join_style); |
306 G("tile:", tile); | 304 FROB (fill_style); |
307 G("stipple:", stipple); | 305 FROB (fill_rule); |
308 G("tsx_origin:", ts_x_origin); | 306 FROB (arc_mode); |
309 G("tsy_origin:", ts_y_origin); | 307 FROB (tile); |
310 G("font:", font); | 308 FROB (stipple); |
311 G("subwindow:", subwindow_mode); | 309 FROB (ts_x_origin); |
312 G("gexposures:", graphics_exposures); | 310 FROB (ts_y_origin); |
313 G("clip_x:", clip_x_origin); | 311 FROB (font); |
314 G("clip_y:", clip_y_origin); | 312 FROB (subwindow_mode); |
315 G("clip_mask:", clip_mask); | 313 FROB (graphics_exposures); |
316 G("dash_off:", dash_offset); | 314 FROB (clip_x_origin); |
317 #undef F | 315 FROB (clip_y_origin); |
318 #undef G | 316 FROB (clip_mask); |
317 FROB (dash_offset); | |
318 #undef FROB | |
319 | |
319 count++; | 320 count++; |
320 if (cell->next && cell == cache->tail) | 321 if (cell->next && cell == cache->tail) |
321 stderr_out ("\nERROR! tail is here!\n\n"); | 322 stderr_out ("\nERROR! tail is here!\n\n"); |
322 else if (!cell->next && cell != cache->tail) | 323 else if (!cell->next && cell != cache->tail) |
323 stderr_out ("\nERROR! tail is not at the end\n\n"); | 324 stderr_out ("\nERROR! tail is not at the end\n\n"); |