From 502ab126ac8d4b87edebb786e69042f13463e525 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 29 Nov 2012 05:29:22 +0000 Subject: [PATCH] * gc.c (gc_stat): prepre Symbol objects at first time to make it fast. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ gc.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index cfe080cb6f..a61e1478f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Nov 29 14:27:57 2012 Koichi Sasada + + * gc.c (gc_stat): prepre Symbol objects at first time + to make it fast. + Thu Nov 29 14:02:15 2012 Koichi Sasada * gc.c (gc_stat): GC.stat supports new information diff --git a/gc.c b/gc.c index ff608e2e9c..8588d5025e 100644 --- a/gc.c +++ b/gc.c @@ -3159,6 +3159,21 @@ gc_stat(int argc, VALUE *argv, VALUE self) { rb_objspace_t *objspace = &rb_objspace; VALUE hash; + static VALUE sym_count; + static VALUE sym_heap_used, sym_heap_length, sym_heap_increment; + static VALUE sym_heap_live_num, sym_heap_free_num, sym_heap_final_num; + static VALUE sym_total_allocated_object, sym_total_freed_object; + if (sym_count == 0) { + sym_count = ID2SYM(rb_intern_const("count")); + sym_heap_used = ID2SYM(rb_intern_const("heap_used")); + sym_heap_length = ID2SYM(rb_intern_const("heap_length")); + sym_heap_increment = ID2SYM(rb_intern_const("heap_increment")); + sym_heap_live_num = ID2SYM(rb_intern_const("heap_live_num")); + sym_heap_free_num = ID2SYM(rb_intern_const("heap_free_num")); + sym_heap_final_num = ID2SYM(rb_intern_const("heap_final_num")); + sym_total_allocated_object = ID2SYM(rb_intern_const("total_allocated_object")); + sym_total_freed_object = ID2SYM(rb_intern_const("total_freed_object")); + } if (rb_scan_args(argc, argv, "01", &hash) == 1) { if (!RB_TYPE_P(hash, T_HASH)) @@ -3171,17 +3186,17 @@ gc_stat(int argc, VALUE *argv, VALUE self) rest_sweep(objspace); - rb_hash_aset(hash, ID2SYM(rb_intern("count")), SIZET2NUM(objspace->count)); - + rb_hash_aset(hash, sym_count, SIZET2NUM(objspace->count)); /* implementation dependent counters */ - rb_hash_aset(hash, ID2SYM(rb_intern("heap_used")), SIZET2NUM(objspace->heap.used)); - rb_hash_aset(hash, ID2SYM(rb_intern("heap_length")), SIZET2NUM(objspace->heap.length)); - rb_hash_aset(hash, ID2SYM(rb_intern("heap_increment")), SIZET2NUM(objspace->heap.increment)); - rb_hash_aset(hash, ID2SYM(rb_intern("heap_live_num")), SIZET2NUM(objspace_live_num(objspace))); - rb_hash_aset(hash, ID2SYM(rb_intern("heap_free_num")), SIZET2NUM(objspace->heap.free_num)); - rb_hash_aset(hash, ID2SYM(rb_intern("heap_final_num")), SIZET2NUM(objspace->heap.final_num)); - rb_hash_aset(hash, ID2SYM(rb_intern("total_allocated_object")), SIZET2NUM(objspace->total_allocated_object_num)); - rb_hash_aset(hash, ID2SYM(rb_intern("total_freed_object")), SIZET2NUM(objspace->total_freed_object_num)); + rb_hash_aset(hash, sym_heap_used, SIZET2NUM(objspace->heap.used)); + rb_hash_aset(hash, sym_heap_length, SIZET2NUM(objspace->heap.length)); + rb_hash_aset(hash, sym_heap_increment, SIZET2NUM(objspace->heap.increment)); + rb_hash_aset(hash, sym_heap_live_num, SIZET2NUM(objspace_live_num(objspace))); + rb_hash_aset(hash, sym_heap_free_num, SIZET2NUM(objspace->heap.free_num)); + rb_hash_aset(hash, sym_heap_final_num, SIZET2NUM(objspace->heap.final_num)); + rb_hash_aset(hash, sym_total_allocated_object, SIZET2NUM(objspace->total_allocated_object_num)); + rb_hash_aset(hash, sym_total_freed_object, SIZET2NUM(objspace->total_freed_object_num)); + return hash; }