diff options
author | Jean Boussier <[email protected]> | 2025-05-10 16:17:11 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-05-10 16:55:22 +0200 |
commit | 6dd7a7bb414040e15c37daa9a968f8959cf6bd49 () | |
tree | c90bd05f5e5128b4c154a5a9942cde7800f3f7cc /variable.c | |
parent | d9502a8386cae343054183e68683d3bbdbb1f383 (diff) |
Refactor `rb_obj_field_get` to handle complex shapes
This allow to get or set fields without having to worry about the shape type.
Notes: Merged: https://.com/ruby/ruby/pull/13297
-rw-r--r-- | variable.c | 38 |
1 files changed, 33 insertions, 5 deletions
@@ -1302,25 +1302,53 @@ VALUE rb_obj_field_get(VALUE obj, rb_shape_t *target_shape) { RUBY_ASSERT(!SPECIAL_CONST_P(obj)); - RUBY_ASSERT(!rb_shape_obj_too_complex_p(obj)); RUBY_ASSERT(target_shape->type == SHAPE_IVAR || target_shape->type == SHAPE_OBJ_ID); - attr_index_t attr_index = target_shape->next_field_index - 1; switch (BUILTIN_TYPE(obj)) { case T_CLASS: case T_MODULE: ASSERT_vm_locking(); - return RCLASS_FIELDS(obj)[attr_index]; case T_OBJECT: - return ROBJECT_FIELDS(obj)[attr_index]; default: RUBY_ASSERT(FL_TEST_RAW(obj, FL_EXIVAR)); struct gen_fields_tbl *fields_tbl = NULL; rb_ivar_generic_fields_tbl_lookup(obj, &fields_tbl); RUBY_ASSERT(fields_tbl); - return fields_tbl->as.shape.fields[attr_index]; } } VALUE |