[#66126] Creation/Conversion methods/functions table for Ruby types — SASADA Koichi <ko1@...>
Hi,
5 messages
2014/11/07
[#66248] [ruby-trunk - Feature #10423] [PATCH] opt_str_lit*: avoid literal string allocations — normalperson@...
Issue #10423 has been updated by Eric Wong.
3 messages
2014/11/13
[#66595] [ruby-trunk - Bug #10557] [Open] Block not given when the argument is a string — bartosz@...
Issue #10557 has been reported by Bartosz Kopinski.
3 messages
2014/11/30
[ruby-core:66430] Re: [ruby-trunk - Bug #10537] Repeated creation and garbage collection of WeakRef instances against a single object leaks memory
From:
Eric Wong <normalperson@...>
Date:
2014-11-24 09:04:29 UTC
List:
ruby-core #66430
Thanks, the following patch should fix it. Your test runs much in less
than 20s and uses 10M on my older x86-64 machine. It took over 2
minutes before.
(lightly tested, and I'm unfamiliar with the weakmap code):
--- a/gc.c
+++ b/gc.c
@@ -2360,6 +2360,21 @@ define_final0(VALUE obj, VALUE block)
if (st_lookup(finalizer_table, obj, &data)) {
table = (VALUE)data;
+
+ /* avoid duplicate block, table is usually small */
+ {
+ const VALUE *ptr = RARRAY_CONST_PTR(table);
+ long len = RARRAY_LEN(table);
+ long i;
+
+ for (i = 0; i < len; i++, ptr++) {
+ if (rb_funcall(*ptr, idEq, 1, block)) {
+ rb_gc_force_recycle(block);
+ return *ptr;
+ }
+ }
+ }
+
rb_ary_push(table, block);
}
else {