Skip to content

Commit 21f6eaa

Browse files
funny-falcontmm1
authored andcommitted
do not grow with a lot of method_missing methods
1 parent e848e3d commit 21f6eaa

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

vm_method.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,23 @@ rb_mcache_resize(struct rb_meth_cache *cache)
7373
tmp.method_state = cache->method_state;
7474
tmp.class_serial = cache->class_serial;
7575
tmp.capa = cache->capa * 2;
76+
redo:
7677
tmp.entries = xcalloc(tmp.capa, sizeof(struct cache_entry));
7778
for(i = 0; i < cache->capa; i++) {
78-
if (cache->entries[i].mid) {
79+
if (cache->entries[i].mid && (cache->entries[i].me & ~1)) {
7980
struct cache_entry *ent = &cache->entries[i];
8081
rb_mcache_insert(&tmp, ent->mid, ent->me & ~1, ent->defined_class);
8182
}
8283
}
84+
/* deal with lots of cached method_missing */
85+
if (tmp.size < tmp.capa / 8) {
86+
xfree(tmp.entries);
87+
while(tmp.capa > tmp.size * 2 && tmp.capa > 8) {
88+
tmp.capa /= 2;
89+
}
90+
tmp.size = 0;
91+
goto redo;
92+
}
8393
xfree(cache->entries);
8494
*cache = tmp;
8595
}

0 commit comments

Comments
 (0)