gc.c: ObjectSpace::WeakMap#size
* gc.c (wmap_size): add ObjectSpace::WeakMap#size and #length. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b73a306441
commit
d2cc188ad5
@ -1,3 +1,7 @@
|
|||||||
|
Mon Dec 9 16:13:31 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* gc.c (wmap_size): add ObjectSpace::WeakMap#size and #length.
|
||||||
|
|
||||||
Mon Dec 9 15:26:17 2013 Shugo Maeda <shugo@ruby-lang.org>
|
Mon Dec 9 15:26:17 2013 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* test/test_curses.rb: removed.
|
* test/test_curses.rb: removed.
|
||||||
|
16
gc.c
16
gc.c
@ -6470,6 +6470,20 @@ wmap_has_key(VALUE self, VALUE key)
|
|||||||
return NIL_P(wmap_aref(self, key)) ? Qfalse : Qtrue;
|
return NIL_P(wmap_aref(self, key)) ? Qfalse : Qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
wmap_size(VALUE self)
|
||||||
|
{
|
||||||
|
struct weakmap *w;
|
||||||
|
st_index_t n;
|
||||||
|
|
||||||
|
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
|
||||||
|
n = w->wmap2obj->num_entries;
|
||||||
|
#if SIZEOF_ST_INDEX_T <= SIZEOF_LONG
|
||||||
|
return ULONG2NUM(n);
|
||||||
|
#else
|
||||||
|
return ULL2NUM(n);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
------------------------------ GC profiler ------------------------------
|
------------------------------ GC profiler ------------------------------
|
||||||
@ -7304,6 +7318,8 @@ Init_GC(void)
|
|||||||
rb_define_method(rb_cWeakMap, "each_value", wmap_each_value, 0);
|
rb_define_method(rb_cWeakMap, "each_value", wmap_each_value, 0);
|
||||||
rb_define_method(rb_cWeakMap, "keys", wmap_keys, 0);
|
rb_define_method(rb_cWeakMap, "keys", wmap_keys, 0);
|
||||||
rb_define_method(rb_cWeakMap, "values", wmap_values, 0);
|
rb_define_method(rb_cWeakMap, "values", wmap_values, 0);
|
||||||
|
rb_define_method(rb_cWeakMap, "size", wmap_size, 0);
|
||||||
|
rb_define_method(rb_cWeakMap, "length", wmap_size, 0);
|
||||||
rb_define_private_method(rb_cWeakMap, "finalize", wmap_finalize, 1);
|
rb_define_private_method(rb_cWeakMap, "finalize", wmap_finalize, 1);
|
||||||
rb_include_module(rb_cWeakMap, rb_mEnumerable);
|
rb_include_module(rb_cWeakMap, rb_mEnumerable);
|
||||||
}
|
}
|
||||||
|
@ -93,4 +93,18 @@ class TestWeakMap < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
assert_equal(2, n)
|
assert_equal(2, n)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_size
|
||||||
|
m = __callee__[/test_(.*)/, 1]
|
||||||
|
assert_equal(0, @wm.__send__(m))
|
||||||
|
x1 = "foo"
|
||||||
|
k1 = Object.new
|
||||||
|
@wm[k1] = x1
|
||||||
|
assert_equal(1, @wm.__send__(m))
|
||||||
|
x2 = "bar"
|
||||||
|
k2 = Object.new
|
||||||
|
@wm[k2] = x2
|
||||||
|
assert_equal(2, @wm.__send__(m))
|
||||||
|
end
|
||||||
|
alias test_length test_size
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user