summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authorAaron Patterson <[email protected]>2023-03-17 11:29:04 -0700
committerAaron Patterson <[email protected]>2023-03-20 13:54:18 -0700
commit54dbd8bea8a79bfcdefa471c1717c6cd28022f33 ()
treea192755d979ae7db2a47616450d8a32332855809 /variable.c
parent51834ff2ec4fba7fa4d62b04365c1c9c5b6700f1 (diff)
Use an st table for "too complex" objects
st tables will maintain insertion order so we can marshal dump / load objects with instance variables in the same order they were set on that particular instance [ruby-core:112926] [Bug #19535] Co-Authored-By: Jemma Issroff <[email protected]>
Notes: Merged: https://.com/ruby/ruby/pull/7560
-rw-r--r--variable.c28
1 files changed, 14 insertions, 14 deletions
@@ -1167,9 +1167,9 @@ rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
shape_id = ROBJECT_SHAPE_ID(obj);
#endif
if (rb_shape_obj_too_complex(obj)) {
- struct rb_id_table * iv_table = ROBJECT_IV_HASH(obj);
VALUE val;
- if (rb_id_table_lookup(iv_table, id, &val)) {
return val;
}
else {
@@ -1426,7 +1426,7 @@ rb_grow_iv_list(VALUE obj)
int
rb_obj_evacuate_ivs_to_hash_table(ID key, VALUE val, st_data_t arg)
{
- rb_id_table_insert((struct rb_id_table *)arg, key, val);
return ST_CONTINUE;
}
@@ -1439,8 +1439,8 @@ rb_obj_ivar_set(VALUE obj, ID id, VALUE val)
uint32_t num_iv = shape->capacity;
if (rb_shape_obj_too_complex(obj)) {
- struct rb_id_table * table = ROBJECT_IV_HASH(obj);
- rb_id_table_insert(table, id, val);
RB_OBJ_WRITTEN(obj, Qundef, val);
return 0;
}
@@ -1463,13 +1463,13 @@ rb_obj_ivar_set(VALUE obj, ID id, VALUE val)
rb_shape_t *next_shape = rb_shape_get_next(shape, obj, id);
if (next_shape->type == SHAPE_OBJ_TOO_COMPLEX) {
- struct rb_id_table * table = rb_id_table_create(shape->next_iv_index);
// Evacuate all previous values from shape into id_table
rb_ivar_foreach(obj, rb_obj_evacuate_ivs_to_hash_table, (st_data_t)table);
// Insert new value too
- rb_id_table_insert(table, id, val);
RB_OBJ_WRITTEN(obj, Qundef, val);
rb_shape_set_too_complex(obj);
@@ -1618,7 +1618,7 @@ rb_ivar_defined(VALUE obj, ID id)
if (SPECIAL_CONST_P(obj)) return Qfalse;
if (rb_shape_obj_too_complex(obj)) {
VALUE idx;
- if (!rb_id_table_lookup(ROBJECT_IV_HASH(obj), id, &idx)) {
return Qfalse;
}
@@ -1677,12 +1677,12 @@ iterate_over_shapes_with_callback(rb_shape_t *shape, rb_ivar_foreach_callback_fu
}
}
-static enum rb_id_table_iterator_result
-each_hash_iv(ID id, VALUE val, void *data)
{
struct iv_itr_data * itr_data = (struct iv_itr_data *)data;
rb_ivar_foreach_callback_func *callback = itr_data->func;
- return callback(id, val, itr_data->arg);
}
static void
@@ -1694,7 +1694,7 @@ obj_ivar_each(VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg)
itr_data.arg = arg;
itr_data.func = func;
if (rb_shape_obj_too_complex(obj)) {
- rb_id_table_foreach(ROBJECT_IV_HASH(obj), each_hash_iv, &itr_data);
}
else {
iterate_over_shapes_with_callback(shape, func, &itr_data);
@@ -1988,8 +1988,8 @@ rb_obj_remove_instance_variable(VALUE obj, VALUE name)
break;
case T_OBJECT: {
if (rb_shape_obj_too_complex(obj)) {
- if (rb_id_table_lookup(ROBJECT_IV_HASH(obj), id, &val)) {
- rb_id_table_delete(ROBJECT_IV_HASH(obj), id);
}
}
else {