summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2023-11-06 08:29:41 -0500
committerPeter Zhu <[email protected]>2023-11-06 11:10:41 -0500
commit679e98dc27c4711601801db8852c5b4bc5a9da76 ()
tree1f98c7a67c0660f6e022b4dffe28d676ecfec8cb /variable.c
parentc747c67533ef901d10ef054d2f57a0b90702c7f9 (diff)
Use general_ivar_set for Objects
-rw-r--r--variable.c80
1 files changed, 35 insertions, 45 deletions
@@ -1676,59 +1676,49 @@ rb_obj_evacuate_ivs_to_hash_table(ID key, VALUE val, st_data_t arg)
return ST_CONTINUE;
}
-attr_index_t
-rb_obj_ivar_set(VALUE obj, ID id, VALUE val)
{
- attr_index_t index;
-
- rb_shape_t *shape = rb_shape_get_shape(obj);
- uint32_t num_iv = shape->capacity;
-
- if (rb_shape_obj_too_complex(obj)) {
- rb_complex_ivar_set(obj, id, val);
- return 0;
- }
-
- rb_shape_t *next_shape;
-
- if (!rb_shape_get_iv_index(shape, id, &index)) {
- index = shape->next_iv_index;
- if (index >= MAX_IVARS) {
- rb_raise(rb_eArgError, "too many instance variables");
- }
- RUBY_ASSERT(!rb_shape_obj_too_complex(obj));
- if (UNLIKELY(shape->next_iv_index >= num_iv)) {
- RUBY_ASSERT(shape->next_iv_index == num_iv);
- next_shape = rb_grow_iv_list(obj);
- if (next_shape->type == SHAPE_OBJ_TOO_COMPLEX) {
- rb_complex_ivar_set(obj, id, val);
- return 0;
- }
- shape = next_shape;
- RUBY_ASSERT(shape->type == SHAPE_CAPACITY_CHANGE);
- }
- next_shape = rb_shape_get_next(shape, obj, id);
- if (next_shape->type == SHAPE_OBJ_TOO_COMPLEX) {
- rb_evict_ivars_to_hash(obj, shape);
- rb_complex_ivar_set(obj, id, val);
- return 0;
- }
- else {
- rb_shape_set_shape(obj, next_shape);
- RUBY_ASSERT(next_shape->type == SHAPE_IVAR);
- RUBY_ASSERT(index == (next_shape->next_iv_index - 1));
- }
- }
- RUBY_ASSERT(!rb_shape_obj_too_complex(obj));
- RB_OBJ_WRITE(obj, &ROBJECT_IVPTR(obj)[index], val);
- return index;
}
/* Set the instance variable +val+ on object +obj+ at ivar name +id+.