@@ -373,8 +373,8 @@ rb_managed_id_table_new(size_t capa)
373373static enum rb_id_table_iterator_result
374374managed_id_table_dup_i (ID id , VALUE val , void * data )
375375{
376- struct rb_id_table * new_tbl = (struct rb_id_table * )data ;
377- rb_id_table_insert ( new_tbl , id , val );
376+ VALUE new_table = (VALUE )data ;
377+ rb_managed_id_table_insert ( new_table , id , val );
378378 return ID_TABLE_CONTINUE ;
379379}
380380
@@ -384,12 +384,9 @@ rb_managed_id_table_dup(VALUE old_table)
384384 RUBY_ASSERT (RB_TYPE_P (old_table , T_DATA ));
385385 RUBY_ASSERT (rb_typeddata_inherited_p (RTYPEDDATA_TYPE (old_table ), & managed_id_table_type ));
386386
387- struct rb_id_table * new_tbl ;
388- VALUE obj = TypedData_Make_Struct (0 , struct rb_id_table , & managed_id_table_type , new_tbl );
389- struct rb_id_table * old_tbl = RTYPEDDATA_GET_DATA (old_table );
390- rb_id_table_init (new_tbl , old_tbl -> num + 1 );
391- rb_id_table_foreach (old_tbl , managed_id_table_dup_i , new_tbl );
392- return obj ;
387+ VALUE new_table = rb_managed_id_table_new (rb_managed_id_table_size (old_table ) + 1 );
388+ rb_managed_id_table_foreach (old_table , managed_id_table_dup_i , (void * )new_table );
389+ return new_table ;
393390}
394391
395392int
@@ -485,21 +482,6 @@ rb_marked_id_table_new(size_t capa)
485482 return obj ;
486483}
487484
488- struct marked_id_table_dup_args {
489- struct rb_id_table * tbl ;
490- VALUE owner ;
491- };
492-
493- static enum rb_id_table_iterator_result
494- marked_id_table_dup_i (ID id , VALUE val , void * data )
495- {
496- struct marked_id_table_dup_args * args = (struct marked_id_table_dup_args * )data ;
497-
498- rb_id_table_insert (args -> tbl , id , val );
499- RB_OBJ_WRITTEN (args -> owner , Qundef , val );
500- return ID_TABLE_CONTINUE ;
501- }
502-
503485size_t
504486rb_marked_id_table_size (VALUE table )
505487{
@@ -509,24 +491,23 @@ rb_marked_id_table_size(VALUE table)
509491 return rb_id_table_size (RTYPEDDATA_GET_DATA (table ));
510492}
511493
494+ static enum rb_id_table_iterator_result
495+ marked_id_table_dup_i (ID id , VALUE val , void * data )
496+ {
497+ VALUE new_table = (VALUE )data ;
498+ rb_marked_id_table_insert (new_table , id , val );
499+ return ID_TABLE_CONTINUE ;
500+ }
501+
512502VALUE
513503rb_marked_id_table_dup (VALUE old_table )
514504{
515505 RUBY_ASSERT (RB_TYPE_P (old_table , T_DATA ));
516506 RUBY_ASSERT (rb_typeddata_inherited_p (RTYPEDDATA_TYPE (old_table ), & marked_id_table_type ));
517507
518- struct rb_id_table * new_tbl ;
519- VALUE obj = TypedData_Make_Struct (0 , struct rb_id_table , & marked_id_table_type , new_tbl );
520- struct rb_id_table * old_tbl = RTYPEDDATA_GET_DATA (old_table );
521-
522- struct marked_id_table_dup_args args = {
523- .tbl = new_tbl ,
524- .owner = obj ,
525- };
526-
527- rb_id_table_init (new_tbl , old_tbl -> num + 1 );
528- rb_id_table_foreach (old_tbl , marked_id_table_dup_i , (void * )& args );
529- return obj ;
508+ VALUE new_table = rb_marked_id_table_new (rb_marked_id_table_size (old_table ) + 1 );
509+ rb_marked_id_table_foreach (old_table , marked_id_table_dup_i , (void * )new_table );
510+ return new_table ;
530511}
531512
532513int
0 commit comments