@@ -1482,6 +1482,7 @@ void
14821482rb_obj_convert_to_too_complex (VALUE obj , st_table * table )
14831483{
14841484 RUBY_ASSERT (!rb_shape_obj_too_complex (obj ));
1485+ rb_shape_t * too_complex_shape = rb_shape_transition_shape_too_complex (obj );
14851486
14861487 VALUE * old_fields = NULL ;
14871488
@@ -1490,13 +1491,13 @@ rb_obj_convert_to_too_complex(VALUE obj, st_table *table)
14901491 if (!(RBASIC (obj )-> flags & ROBJECT_EMBED )) {
14911492 old_fields = ROBJECT_FIELDS (obj );
14921493 }
1493- rb_shape_set_shape_id (obj , OBJ_TOO_COMPLEX_SHAPE_ID );
1494+ rb_shape_set_shape (obj , too_complex_shape );
14941495 ROBJECT_SET_FIELDS_HASH (obj , table );
14951496 break ;
14961497 case T_CLASS :
14971498 case T_MODULE :
14981499 old_fields = RCLASS_FIELDS (obj );
1499- rb_shape_set_shape_id (obj , OBJ_TOO_COMPLEX_SHAPE_ID );
1500+ rb_shape_set_shape (obj , too_complex_shape );
15001501 RCLASS_SET_FIELDS_HASH (obj , table );
15011502 break ;
15021503 default :
@@ -1513,9 +1514,9 @@ rb_obj_convert_to_too_complex(VALUE obj, st_table *table)
15131514 * compaction. We want the table to be updated rather than
15141515 * the original fields. */
15151516#if SHAPE_IN_BASIC_FLAGS
1516- rb_shape_set_shape_id (obj , OBJ_TOO_COMPLEX_SHAPE_ID );
1517+ rb_shape_set_shape (obj , too_complex_shape );
15171518#else
1518- old_fields_tbl -> shape_id = OBJ_TOO_COMPLEX_SHAPE_ID ;
1519+ old_fields_tbl -> shape_id = rb_shape_id ( too_complex_shape ) ;
15191520#endif
15201521 old_fields_tbl -> as .complex .table = table ;
15211522 old_fields = (VALUE * )old_fields_tbl ;
@@ -1524,10 +1525,11 @@ rb_obj_convert_to_too_complex(VALUE obj, st_table *table)
15241525 struct gen_fields_tbl * fields_tbl = xmalloc (sizeof (struct gen_fields_tbl ));
15251526 fields_tbl -> as .complex .table = table ;
15261527 st_insert (gen_ivs , (st_data_t )obj , (st_data_t )fields_tbl );
1528+
15271529#if SHAPE_IN_BASIC_FLAGS
1528- rb_shape_set_shape_id (obj , OBJ_TOO_COMPLEX_SHAPE_ID );
1530+ rb_shape_set_shape (obj , too_complex_shape );
15291531#else
1530- fields_tbl -> shape_id = OBJ_TOO_COMPLEX_SHAPE_ID ;
1532+ fields_tbl -> shape_id = rb_shape_id ( too_complex_shape ) ;
15311533#endif
15321534 }
15331535 RB_VM_LOCK_LEAVE ();
@@ -1570,7 +1572,7 @@ general_ivar_set(VALUE obj, ID id, VALUE val, void *data,
15701572
15711573 rb_shape_t * current_shape = rb_shape_get_shape (obj );
15721574
1573- if (UNLIKELY (current_shape -> type == SHAPE_OBJ_TOO_COMPLEX )) {
1575+ if (UNLIKELY (rb_shape_too_complex_p ( current_shape ) )) {
15741576 goto too_complex ;
15751577 }
15761578
@@ -1584,7 +1586,7 @@ general_ivar_set(VALUE obj, ID id, VALUE val, void *data,
15841586 }
15851587
15861588 rb_shape_t * next_shape = rb_shape_get_next (current_shape , obj , id );
1587- if (UNLIKELY (next_shape -> type == SHAPE_OBJ_TOO_COMPLEX )) {
1589+ if (UNLIKELY (rb_shape_too_complex_p ( next_shape ) )) {
15881590 transition_too_complex_func (obj , data );
15891591 goto too_complex ;
15901592 }
@@ -1709,7 +1711,7 @@ generic_ivar_set_too_complex_table(VALUE obj, void *data)
17091711 if (!rb_gen_fields_tbl_get (obj , 0 , & fields_tbl )) {
17101712 fields_tbl = xmalloc (sizeof (struct gen_fields_tbl ));
17111713#if !SHAPE_IN_BASIC_FLAGS
1712- fields_tbl -> shape_id = OBJ_TOO_COMPLEX_SHAPE_ID ;
1714+ fields_tbl -> shape_id = rb_shape_id ( rb_shape_transition_shape_too_complex ( obj )) ;
17131715#endif
17141716 fields_tbl -> as .complex .table = st_init_numtable_with_size (1 );
17151717
@@ -1886,7 +1888,7 @@ void rb_obj_freeze_inline(VALUE x)
18861888
18871889 // If we're transitioning from "not complex" to "too complex"
18881890 // then evict ivars. This can happen if we run out of shapes
1889- if (!rb_shape_obj_too_complex (x ) && next_shape -> type == SHAPE_OBJ_TOO_COMPLEX ) {
1891+ if (!rb_shape_obj_too_complex (x ) && rb_shape_too_complex_p ( next_shape ) ) {
18901892 rb_evict_ivars_to_hash (x );
18911893 }
18921894 rb_shape_set_shape (x , next_shape );
@@ -2029,7 +2031,6 @@ iterate_over_shapes_with_callback(rb_shape_t *shape, rb_ivar_foreach_callback_fu
20292031 case SHAPE_FROZEN :
20302032 return iterate_over_shapes_with_callback (rb_shape_get_parent (shape ), callback , itr_data );
20312033 case SHAPE_OBJ_TOO_COMPLEX :
2032- default :
20332034 rb_bug ("Unreachable" );
20342035 }
20352036}
@@ -2117,7 +2118,7 @@ rb_copy_generic_ivar(VALUE clone, VALUE obj)
21172118 if (rb_shape_obj_too_complex (obj )) {
21182119 new_fields_tbl = xmalloc (sizeof (struct gen_fields_tbl ));
21192120#if !SHAPE_IN_BASIC_FLAGS
2120- new_fields_tbl -> shape_id = OBJ_TOO_COMPLEX_SHAPE_ID ;
2121+ new_fields_tbl -> shape_id = old_fields_tbl -> shape_id ;
21212122#endif
21222123 new_fields_tbl -> as .complex .table = st_copy (obj_fields_tbl -> as .complex .table );
21232124 }
@@ -2140,7 +2141,7 @@ rb_copy_generic_ivar(VALUE clone, VALUE obj)
21402141 }
21412142 RB_VM_LOCK_LEAVE ();
21422143
2143- rb_shape_t * obj_shape = rb_shape_get_shape (obj );
2144+ rb_shape_t * obj_shape = rb_shape_get_shape (obj );
21442145 if (rb_shape_frozen_shape_p (obj_shape )) {
21452146 rb_shape_set_shape_id (clone , obj_shape -> parent_id );
21462147 }
0 commit comments