From 5ef019e8afca25442c7c12eea8822d88978141bb Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 4 May 2020 11:33:00 -0700 Subject: [PATCH] Output compaction stats in one loop / eliminate 0 counts We only need to loop `T_MASK` times once. Also, not every value between 0 and `T_MASK` is an actual Ruby type. Before this change, some integers were being added to the result hash even though they aren't actual types. This patch omits considered / moved entries that total 0, cleaning up the result hash and eliminating these "fake types". --- gc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gc.c b/gc.c index fb167bf7d5..a3f2de74aa 100644 --- a/gc.c +++ b/gc.c @@ -8509,11 +8509,13 @@ gc_compact_stats(rb_objspace_t *objspace) VALUE moved = rb_hash_new(); for (i=0; ircompactor.considered_count_table[i])); - } + if(objspace->rcompactor.considered_count_table[i]) { + rb_hash_aset(considered, type_sym(i), SIZET2NUM(objspace->rcompactor.considered_count_table[i])); + } - for (i=0; ircompactor.moved_count_table[i])); + if(objspace->rcompactor.moved_count_table[i]) { + rb_hash_aset(moved, type_sym(i), SIZET2NUM(objspace->rcompactor.moved_count_table[i])); + } } rb_hash_aset(h, ID2SYM(rb_intern("considered")), considered);