@@ -4535,43 +4535,30 @@ rb_iv_set(VALUE obj, const char *name, VALUE val)
4535
4535
static bool
4536
4536
class_fields_ivar_set (VALUE klass , VALUE fields_obj , ID id , VALUE val , bool concurrent , VALUE * new_fields_obj )
4537
4537
{
4538
- bool existing = true;
4539
4538
const VALUE original_fields_obj = fields_obj ;
4540
4539
fields_obj = original_fields_obj ? original_fields_obj : rb_imemo_fields_new (klass , 1 );
4541
4540
4542
4541
shape_id_t current_shape_id = RBASIC_SHAPE_ID (fields_obj );
4543
- shape_id_t next_shape_id = current_shape_id ;
4544
4542
4545
4543
if (UNLIKELY (rb_shape_too_complex_p (current_shape_id ))) {
4546
4544
goto too_complex ;
4547
4545
}
4548
4546
4549
- attr_index_t index ;
4550
- if (!rb_shape_get_iv_index (current_shape_id , id , & index )) {
4551
- existing = false;
4552
-
4553
- index = RSHAPE_LEN (current_shape_id );
4554
- if (index >= SHAPE_MAX_FIELDS ) {
4555
- rb_raise (rb_eArgError , "too many instance variables" );
4556
- }
4557
-
4558
- next_shape_id = rb_shape_transition_add_ivar (fields_obj , id );
4559
- if (UNLIKELY (rb_shape_too_complex_p (next_shape_id ))) {
4560
- fields_obj = imemo_fields_complex_from_obj (klass , fields_obj , next_shape_id );
4561
- goto too_complex ;
4562
- }
4547
+ bool new_ivar ;
4548
+ shape_id_t next_shape_id = generic_shape_ivar (fields_obj , id , & new_ivar );
4563
4549
4564
- attr_index_t next_capacity = RSHAPE_CAPACITY (next_shape_id );
4565
- attr_index_t current_capacity = RSHAPE_CAPACITY (current_shape_id );
4550
+ if (UNLIKELY (rb_shape_too_complex_p (next_shape_id ))) {
4551
+ fields_obj = imemo_fields_complex_from_obj (klass , fields_obj , next_shape_id );
4552
+ goto too_complex ;
4553
+ }
4566
4554
4567
- if (next_capacity > current_capacity ) {
4555
+ attr_index_t index = RSHAPE_INDEX (next_shape_id );
4556
+ if (new_ivar ) {
4557
+ if (index >= RSHAPE_CAPACITY (current_shape_id )) {
4568
4558
// We allocate a new fields_obj even when concurrency isn't a concern
4569
4559
// so that we're embedded as long as possible.
4570
- fields_obj = imemo_fields_copy_capa (klass , fields_obj , next_capacity );
4560
+ fields_obj = imemo_fields_copy_capa (klass , fields_obj , RSHAPE_CAPACITY ( next_shape_id ) );
4571
4561
}
4572
-
4573
- RUBY_ASSERT (RSHAPE (next_shape_id )-> type == SHAPE_IVAR );
4574
- RUBY_ASSERT (index == (RSHAPE_LEN (next_shape_id ) - 1 ));
4575
4562
}
4576
4563
4577
4564
VALUE * fields = rb_imemo_fields_ptr (fields_obj );
@@ -4588,12 +4575,12 @@ class_fields_ivar_set(VALUE klass, VALUE fields_obj, ID id, VALUE val, bool conc
4588
4575
RB_OBJ_WRITE (fields_obj , & fields [index ], val );
4589
4576
}
4590
4577
4591
- if (! existing ) {
4578
+ if (new_ivar ) {
4592
4579
RBASIC_SET_SHAPE_ID (fields_obj , next_shape_id );
4593
4580
}
4594
4581
4595
4582
* new_fields_obj = fields_obj ;
4596
- return existing ;
4583
+ return new_ivar ;
4597
4584
4598
4585
too_complex :
4599
4586
{
@@ -4605,7 +4592,7 @@ class_fields_ivar_set(VALUE klass, VALUE fields_obj, ID id, VALUE val, bool conc
4605
4592
}
4606
4593
4607
4594
st_table * table = rb_imemo_fields_complex_tbl (fields_obj );
4608
- existing = st_insert (table , (st_data_t )id , (st_data_t )val );
4595
+ new_ivar = ! st_insert (table , (st_data_t )id , (st_data_t )val );
4609
4596
RB_OBJ_WRITTEN (fields_obj , Qundef , val );
4610
4597
4611
4598
if (fields_obj != original_fields_obj ) {
@@ -4614,7 +4601,7 @@ class_fields_ivar_set(VALUE klass, VALUE fields_obj, ID id, VALUE val, bool conc
4614
4601
}
4615
4602
4616
4603
* new_fields_obj = fields_obj ;
4617
- return existing ;
4604
+ return new_ivar ;
4618
4605
}
4619
4606
4620
4607
bool
@@ -4628,7 +4615,7 @@ rb_class_ivar_set(VALUE obj, ID id, VALUE val)
4628
4615
const VALUE original_fields_obj = RCLASS_WRITABLE_FIELDS_OBJ (obj );
4629
4616
VALUE new_fields_obj = 0 ;
4630
4617
4631
- bool existing = class_fields_ivar_set (obj , original_fields_obj , id , val , rb_multi_ractor_p (), & new_fields_obj );
4618
+ bool new_ivar = class_fields_ivar_set (obj , original_fields_obj , id , val , rb_multi_ractor_p (), & new_fields_obj );
4632
4619
4633
4620
if (new_fields_obj != original_fields_obj ) {
4634
4621
RCLASS_WRITABLE_SET_FIELDS_OBJ (obj , new_fields_obj );
@@ -4640,7 +4627,7 @@ rb_class_ivar_set(VALUE obj, ID id, VALUE val)
4640
4627
// Perhaps INVALID_SHAPE_ID?
4641
4628
RBASIC_SET_SHAPE_ID (obj , RBASIC_SHAPE_ID (new_fields_obj ));
4642
4629
4643
- return ! existing ;
4630
+ return new_ivar ;
4644
4631
}
4645
4632
4646
4633
void
0 commit comments