summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-19 05:09:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-06-19 05:09:32 +0000
commitcb2cf70aa1b8856aef3cfff16141579bcf2a97ac (patch)
tree30515583db0946e538b58251d0e935851b11d8a1 /gc.c
parentff117cb3b71fac11f66626c4bb5c885886a4c506 (diff)
* gc.c (run_final): reduce unnecessary object allocation during
finalization. * gc.c (rb_gc_call_finalizer_at_exit): deferred finalizers list should be cleared before calling them. fixed: [ruby-talk:145790] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/gc.c b/gc.c
index fdcff70..b0b20d1 100644
--- a/gc.c
+++ b/gc.c
@@ -1787,17 +1787,20 @@ run_final(obj)
int status, critical_save = rb_thread_critical;
VALUE args[3], table;
+ objid = rb_obj_id(obj); /* make obj into id */
rb_thread_critical = Qtrue;
- args[1] = rb_ary_new3(1, rb_obj_id(obj)); /* make obj into id */
+ args[1] = 0;
args[2] = (VALUE)ruby_safe_level;
for (i=0; i<RARRAY(finalizers)->len; i++) {
args[0] = RARRAY(finalizers)->ptr[i];
+ if (!args[1]) args[1] = rb_ary_new3(1, objid);
rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);
}
if (finalizer_table && st_delete(finalizer_table, (st_data_t*)&obj, &table)) {
for (i=0; i<RARRAY(table)->len; i++) {
VALUE final = RARRAY(table)->ptr[i];
args[0] = RARRAY(final)->ptr[1];
+ if (!args[1]) args[1] = rb_ary_new3(1, objid);
args[2] = FIX2INT(RARRAY(final)->ptr[0]);
rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);
}
@@ -1825,7 +1828,9 @@ rb_gc_call_finalizer_at_exit()
/* run finalizers */
if (need_call_final) {
- finalize_list(deferred_final_list);
+ p = deferred_final_list;
+ deferred_final_list = 0;
+ finalize_list(p);
for (i = 0; i < heaps_used; i++) {
p = heaps[i].slot; pend = p + heaps[i].limit;
while (p < pend) {