Skip to content

Commit 7989a2f

Browse files
committed
Preallocate capacity for id table in rb_singleton_class_clone_and_attach
We know the exact capacity for the constant table created in rb_singleton_class_clone_and_attach so we can preallocate it.
1 parent 9b22169 commit 7989a2f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

class.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
11931193
if (RCLASS_CONST_TBL(klass)) {
11941194
struct clone_const_arg arg;
11951195
struct rb_id_table *table;
1196-
arg.tbl = table = rb_id_table_create(0);
1196+
arg.tbl = table = rb_id_table_create(rb_id_table_size(RCLASS_CONST_TBL(klass)));
11971197
arg.klass = clone;
11981198
rb_id_table_foreach(RCLASS_CONST_TBL(klass), clone_const_i, &arg);
11991199
RCLASS_SET_CONST_TBL(clone, table, false);

0 commit comments

Comments
 (0)