1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/objspace/objspace.c (setup_hash): unify common routine.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2015-04-10 10:13:00 +00:00
parent ff381ca19b
commit 1a688f001c
2 changed files with 27 additions and 27 deletions

View file

@ -1,3 +1,7 @@
Fri Apr 10 19:10:34 2015 Koichi Sasada <ko1@atdot.net>
* ext/objspace/objspace.c (setup_hash): unify common routine.
Fri Apr 10 18:29:49 2015 Tanaka Akira <akr@fsij.org>
* process.c (rb_execarg_parent_start1): Handle EINTR.

View file

@ -125,6 +125,26 @@ set_zero_i(st_data_t key, st_data_t val, st_data_t arg)
return ST_CONTINUE;
}
static VALUE
setup_hash(int argc, VALUE *argv)
{
VALUE hash;
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
if (!RB_TYPE_P(hash, T_HASH))
rb_raise(rb_eTypeError, "non-hash given");
}
if (hash == Qnil) {
hash = rb_hash_new();
}
else if (!RHASH_EMPTY_P(hash)) {
st_foreach(RHASH_TBL(hash), set_zero_i, hash);
}
return hash;
}
static int
cos_i(void *vstart, void *vend, size_t stride, void *data)
{
@ -206,12 +226,7 @@ count_objects_size(int argc, VALUE *argv, VALUE os)
size_t counts[T_MASK+1];
size_t total = 0;
enum ruby_value_type i;
VALUE hash;
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
if (!RB_TYPE_P(hash, T_HASH))
rb_raise(rb_eTypeError, "non-hash given");
}
VALUE hash = setup_hash(argc, argv);
for (i = 0; i <= T_MASK; i++) {
counts[i] = 0;
@ -281,12 +296,7 @@ count_nodes(int argc, VALUE *argv, VALUE os)
{
size_t nodes[NODE_LAST+1];
size_t i;
VALUE hash;
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
if (!RB_TYPE_P(hash, T_HASH))
rb_raise(rb_eTypeError, "non-hash given");
}
VALUE hash = setup_hash(argc, argv);
for (i = 0; i <= NODE_LAST; i++) {
nodes[i] = 0;
@ -485,22 +495,8 @@ cto_i(void *vstart, void *vend, size_t stride, void *data)
static VALUE
count_tdata_objects(int argc, VALUE *argv, VALUE self)
{
VALUE hash;
if (rb_scan_args(argc, argv, "01", &hash) == 1) {
if (!RB_TYPE_P(hash, T_HASH))
rb_raise(rb_eTypeError, "non-hash given");
}
if (hash == Qnil) {
hash = rb_hash_new();
}
else if (!RHASH_EMPTY_P(hash)) {
st_foreach(RHASH_TBL(hash), set_zero_i, hash);
}
VALUE hash = setup_hash(argc, argv);
rb_objspace_each_objects(cto_i, (void *)hash);
return hash;
}