aboutsummaryrefslogtreecommitdiffstats
path: root/class.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-29 20:19:14 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-29 20:19:14 +0000
commitdbd394967895bda6da524025ef395b6fdad120f2 (patch)
tree6aa658f38ea6cc1181814a627a1cd350af1fdf8e /class.c
parent14e8a7c057be1638437e6efcba356dfc59398914 (diff)
downloadruby-dbd394967895bda6da524025ef395b6fdad120f2.tar.gz
use id_table for constant tables
valgrind 3.9.0 on x86-64 reports a minor reduction in memory usage when loading only RubyGems and RDoc by running: ruby -rrdoc -eexit before: HEAP SUMMARY: in use at exit: 2,913,448 bytes in 27,394 blocks total heap usage: 48,362 allocs, 20,968 frees, 9,034,621 bytes alloc after: HEAP SUMMARY: in use at exit: 2,880,056 bytes in 26,712 blocks total heap usage: 47,791 allocs, 21,079 frees, 9,046,507 bytes alloc * class.c (struct clone_const_arg): adjust for id_table (clone_const): ditto (clone_const_i): ditto (rb_mod_init_copy): ditto (rb_singleton_class_clone_and_attach): ditto (rb_include_class_new): ditto (include_modules_at): ditto * constant.h (rb_free_const_table): ditto * gc.c (free_const_entry_i): ditto (rb_free_const_table): ditto (obj_memsize_of): ditto (mark_const_entry_i): ditto (mark_const_tbl): ditto * internal.h (struct rb_classext_struct): ditto * object.c (rb_mod_const_set): resolve class name on assignment * variable.c (const_update): replace with const_tbl_update (const_tbl_update): new function (fc_i): adjust for id_table (find_class_path): ditto (autoload_const_set): st_update => const_tbl_update (rb_const_remove): adjust for id_table (sv_i): ditto (rb_local_constants_i): ditto (rb_local_constants): ditto (rb_mod_const_at): ditto (rb_mod_const_set): ditto (rb_const_lookup): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/class.c b/class.c
index a72f4dcebd..5c72a4b3c9 100644
--- a/class.c
+++ b/class.c
@@ -274,7 +274,7 @@ clone_method_i(ID key, VALUE value, void *data)
struct clone_const_arg {
VALUE klass;
- st_table *tbl;
+ struct rb_id_table *tbl;
};
static int
@@ -285,14 +285,14 @@ clone_const(ID key, const rb_const_entry_t *ce, struct clone_const_arg *arg)
RB_OBJ_WRITTEN(arg->klass, Qundef, ce->value);
RB_OBJ_WRITTEN(arg->klass, Qundef, ce->file);
- st_insert(arg->tbl, key, (st_data_t)nce);
- return ST_CONTINUE;
+ rb_id_table_insert(arg->tbl, key, (VALUE)nce);
+ return ID_TABLE_CONTINUE;
}
-static int
-clone_const_i(st_data_t key, st_data_t value, st_data_t data)
+static enum rb_id_table_iterator_result
+clone_const_i(ID key, VALUE value, void *data)
{
- return clone_const((ID)key, (const rb_const_entry_t *)value, (struct clone_const_arg *)data);
+ return clone_const(key, (const rb_const_entry_t *)value, data);
}
static void
@@ -346,10 +346,9 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
if (RCLASS_CONST_TBL(orig)) {
struct clone_const_arg arg;
- RCLASS_CONST_TBL(clone) = st_init_numtable();
+ arg.tbl = RCLASS_CONST_TBL(clone) = rb_id_table_create(0);
arg.klass = clone;
- arg.tbl = RCLASS_CONST_TBL(clone);
- st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)&arg);
+ rb_id_table_foreach(RCLASS_CONST_TBL(orig), clone_const_i, &arg);
}
if (RCLASS_M_TBL(orig)) {
struct clone_method_arg arg;
@@ -393,10 +392,9 @@ rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
}
if (RCLASS_CONST_TBL(klass)) {
struct clone_const_arg arg;
- RCLASS_CONST_TBL(clone) = st_init_numtable();
+ arg.tbl = RCLASS_CONST_TBL(clone) = rb_id_table_create(0);
arg.klass = clone;
- arg.tbl = RCLASS_CONST_TBL(clone);
- st_foreach(RCLASS_CONST_TBL(klass), clone_const_i, (st_data_t)&arg);
+ rb_id_table_foreach(RCLASS_CONST_TBL(klass), clone_const_i, &arg);
}
if (attach != Qundef) {
rb_singleton_class_attached(clone, attach);
@@ -823,7 +821,7 @@ rb_include_class_new(VALUE module, VALUE super)
RCLASS_IV_TBL(module) = st_init_numtable();
}
if (!RCLASS_CONST_TBL(module)) {
- RCLASS_CONST_TBL(module) = st_init_numtable();
+ RCLASS_CONST_TBL(module) = rb_id_table_create(0);
}
RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module);
@@ -880,6 +878,7 @@ include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super)
while (module) {
int superclass_seen = FALSE;
+ struct rb_id_table *tbl;
if (RCLASS_ORIGIN(module) != module)
goto skip;
@@ -917,8 +916,12 @@ include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super)
rb_id_table_foreach(RMODULE_M_TBL(module), add_refined_method_entry_i, (void *)refined_class);
FL_SET(c, RMODULE_INCLUDED_INTO_REFINEMENT);
}
- if (RMODULE_M_TBL(module) && rb_id_table_size(RMODULE_M_TBL(module))) method_changed = 1;
- if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries) constant_changed = 1;
+
+ tbl = RMODULE_M_TBL(module);
+ if (tbl && rb_id_table_size(tbl)) method_changed = 1;
+
+ tbl = RMODULE_CONST_TBL(module);
+ if (tbl && rb_id_table_size(tbl)) constant_changed = 1;
skip:
module = RCLASS_SUPER(module);
}