Mercurial > emacs
comparison src/fns.c @ 90972:4849bddaf0d1
* fns.c (weak_hash_tables): Rename from Vweak_hash_tables and change its type.
(make_hash_table, copy_hash_table, sweep_weak_hash_tables, init_fns):
Update to the new type of weak_hash_tables and next_weak.
* lisp.h (struct Lisp_Hash_Table): Change next_weak from Lisp_Object to
a plain C pointer to Lisp_Hash_Table.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 29 Jun 2007 03:48:22 +0000 |
parents | 3371fc48749b |
children | f55f9811f5d7 |
comparison
equal
deleted
inserted
replaced
90971:2acda4a4ac92 | 90972:4849bddaf0d1 |
---|---|
3639 if a `:linear-search t' argument is given to make-hash-table. */ | 3639 if a `:linear-search t' argument is given to make-hash-table. */ |
3640 | 3640 |
3641 | 3641 |
3642 /* The list of all weak hash tables. Don't staticpro this one. */ | 3642 /* The list of all weak hash tables. Don't staticpro this one. */ |
3643 | 3643 |
3644 Lisp_Object Vweak_hash_tables; | 3644 struct Lisp_Hash_Table *weak_hash_tables; |
3645 | 3645 |
3646 /* Various symbols. */ | 3646 /* Various symbols. */ |
3647 | 3647 |
3648 Lisp_Object Qhash_table_p, Qeq, Qeql, Qequal, Qkey, Qvalue; | 3648 Lisp_Object Qhash_table_p, Qeq, Qeql, Qequal, Qkey, Qvalue; |
3649 Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness; | 3649 Lisp_Object QCtest, QCsize, QCrehash_size, QCrehash_threshold, QCweakness; |
3985 xassert (HASH_TABLE_P (table)); | 3985 xassert (HASH_TABLE_P (table)); |
3986 xassert (XHASH_TABLE (table) == h); | 3986 xassert (XHASH_TABLE (table) == h); |
3987 | 3987 |
3988 /* Maybe add this hash table to the list of all weak hash tables. */ | 3988 /* Maybe add this hash table to the list of all weak hash tables. */ |
3989 if (NILP (h->weak)) | 3989 if (NILP (h->weak)) |
3990 h->next_weak = Qnil; | 3990 h->next_weak = NULL; |
3991 else | 3991 else |
3992 { | 3992 { |
3993 h->next_weak = Vweak_hash_tables; | 3993 h->next_weak = weak_hash_tables; |
3994 Vweak_hash_tables = table; | 3994 weak_hash_tables = h; |
3995 } | 3995 } |
3996 | 3996 |
3997 return table; | 3997 return table; |
3998 } | 3998 } |
3999 | 3999 |
4020 XSET_HASH_TABLE (table, h2); | 4020 XSET_HASH_TABLE (table, h2); |
4021 | 4021 |
4022 /* Maybe add this hash table to the list of all weak hash tables. */ | 4022 /* Maybe add this hash table to the list of all weak hash tables. */ |
4023 if (!NILP (h2->weak)) | 4023 if (!NILP (h2->weak)) |
4024 { | 4024 { |
4025 h2->next_weak = Vweak_hash_tables; | 4025 h2->next_weak = weak_hash_tables; |
4026 Vweak_hash_tables = table; | 4026 weak_hash_tables = h2; |
4027 } | 4027 } |
4028 | 4028 |
4029 return table; | 4029 return table; |
4030 } | 4030 } |
4031 | 4031 |
4345 from Vweak_hash_tables. Called from gc_sweep. */ | 4345 from Vweak_hash_tables. Called from gc_sweep. */ |
4346 | 4346 |
4347 void | 4347 void |
4348 sweep_weak_hash_tables () | 4348 sweep_weak_hash_tables () |
4349 { | 4349 { |
4350 Lisp_Object table, used, next; | 4350 struct Lisp_Hash_Table *h, *used, *next; |
4351 struct Lisp_Hash_Table *h; | |
4352 int marked; | 4351 int marked; |
4353 | 4352 |
4354 /* Mark all keys and values that are in use. Keep on marking until | 4353 /* Mark all keys and values that are in use. Keep on marking until |
4355 there is no more change. This is necessary for cases like | 4354 there is no more change. This is necessary for cases like |
4356 value-weak table A containing an entry X -> Y, where Y is used in a | 4355 value-weak table A containing an entry X -> Y, where Y is used in a |
4358 tables, X -> Y might be removed from A, although when looking at B | 4357 tables, X -> Y might be removed from A, although when looking at B |
4359 one finds that it shouldn't. */ | 4358 one finds that it shouldn't. */ |
4360 do | 4359 do |
4361 { | 4360 { |
4362 marked = 0; | 4361 marked = 0; |
4363 for (table = Vweak_hash_tables; !NILP (table); table = h->next_weak) | 4362 for (h = weak_hash_tables; h; h = h->next_weak) |
4364 { | 4363 { |
4365 h = XHASH_TABLE (table); | |
4366 if (h->size & ARRAY_MARK_FLAG) | 4364 if (h->size & ARRAY_MARK_FLAG) |
4367 marked |= sweep_weak_table (h, 0); | 4365 marked |= sweep_weak_table (h, 0); |
4368 } | 4366 } |
4369 } | 4367 } |
4370 while (marked); | 4368 while (marked); |
4371 | 4369 |
4372 /* Remove tables and entries that aren't used. */ | 4370 /* Remove tables and entries that aren't used. */ |
4373 for (table = Vweak_hash_tables, used = Qnil; !NILP (table); table = next) | 4371 for (h = weak_hash_tables, used = NULL; h; h = next) |
4374 { | 4372 { |
4375 h = XHASH_TABLE (table); | |
4376 next = h->next_weak; | 4373 next = h->next_weak; |
4377 | 4374 |
4378 if (h->size & ARRAY_MARK_FLAG) | 4375 if (h->size & ARRAY_MARK_FLAG) |
4379 { | 4376 { |
4380 /* TABLE is marked as used. Sweep its contents. */ | 4377 /* TABLE is marked as used. Sweep its contents. */ |
4381 if (XFASTINT (h->count) > 0) | 4378 if (XFASTINT (h->count) > 0) |
4382 sweep_weak_table (h, 1); | 4379 sweep_weak_table (h, 1); |
4383 | 4380 |
4384 /* Add table to the list of used weak hash tables. */ | 4381 /* Add table to the list of used weak hash tables. */ |
4385 h->next_weak = used; | 4382 h->next_weak = used; |
4386 used = table; | 4383 used = h; |
4387 } | 4384 } |
4388 } | 4385 } |
4389 | 4386 |
4390 Vweak_hash_tables = used; | 4387 weak_hash_tables = used; |
4391 } | 4388 } |
4392 | 4389 |
4393 | 4390 |
4394 | 4391 |
4395 /*********************************************************************** | 4392 /*********************************************************************** |
5275 | 5272 |
5276 | 5273 |
5277 void | 5274 void |
5278 init_fns () | 5275 init_fns () |
5279 { | 5276 { |
5280 Vweak_hash_tables = Qnil; | 5277 weak_hash_tables = NULL; |
5281 } | 5278 } |
5282 | 5279 |
5283 /* arch-tag: 787f8219-5b74-46bd-8469-7e1cc475fa31 | 5280 /* arch-tag: 787f8219-5b74-46bd-8469-7e1cc475fa31 |
5284 (do not change this comment) */ | 5281 (do not change this comment) */ |