Skip to content

Commit 1dda223

Browse files
committed
Get rid of SHAPE_T_OBJECT
Now the `heap_index` is stored as flags inside `shape_id_t`. This saves having to rebuild the entire tree when moving from one slot size to the other.
1 parent 218241b commit 1dda223

9 files changed

Lines changed: 137 additions & 186 deletions

File tree

ext/objspace/objspace_dump.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,6 @@ shape_id_i(shape_id_t shape_id, void *data)
817817
dump_append(dc, ",\"edge_name\":");
818818
dump_append_id(dc, shape->edge_name);
819819

820-
break;
821-
case SHAPE_T_OBJECT:
822-
dump_append(dc, ", \"shape_type\":\"T_OBJECT\"");
823820
break;
824821
case SHAPE_OBJ_ID:
825822
dump_append(dc, ", \"shape_type\":\"OBJ_ID\"");

gc.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -381,19 +381,7 @@ rb_gc_set_shape(VALUE obj, uint32_t shape_id)
381381
uint32_t
382382
rb_gc_rebuild_shape(VALUE obj, size_t heap_id)
383383
{
384-
shape_id_t orig_shape_id = rb_obj_shape_id(obj);
385-
if (rb_shape_too_complex_p(orig_shape_id)) {
386-
return (uint32_t)orig_shape_id;
387-
}
388-
389-
shape_id_t initial_shape_id = rb_shape_root(heap_id);
390-
shape_id_t new_shape_id = rb_shape_traverse_from_new_root(initial_shape_id, orig_shape_id);
391-
392-
if (new_shape_id == INVALID_SHAPE_ID) {
393-
return 0;
394-
}
395-
396-
return (uint32_t)new_shape_id;
384+
return (uint32_t)rb_shape_transition_heap(obj, heap_id);
397385
}
398386

399387
void rb_vm_update_references(void *ptr);
@@ -1925,6 +1913,7 @@ object_id0(VALUE obj)
19251913
// rb_shape_object_id_shape may lock if the current shape has
19261914
// multiple children.
19271915
shape_id_t object_id_shape_id = rb_shape_transition_object_id(obj);
1916+
RUBY_ASSERT(rb_shape_has_object_id(object_id_shape_id));
19281917

19291918
id = generate_next_object_id();
19301919
rb_obj_field_set(obj, object_id_shape_id, id);

object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
339339
shape_id_t dest_shape_id = src_shape_id;
340340
shape_id_t initial_shape_id = RBASIC_SHAPE_ID(dest);
341341

342-
RUBY_ASSERT(RSHAPE(initial_shape_id)->type == SHAPE_T_OBJECT);
342+
RUBY_ASSERT(RSHAPE(initial_shape_id)->type == SHAPE_ROOT);
343343

344344
dest_shape_id = rb_shape_rebuild(initial_shape_id, src_shape_id);
345345
if (UNLIKELY(rb_shape_too_complex_p(dest_shape_id))) {
@@ -363,7 +363,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
363363
}
364364

365365
rb_shape_copy_fields(dest, dest_buf, dest_shape_id, obj, src_buf, src_shape_id);
366-
rb_obj_set_shape_id(dest, dest_shape_id);
366+
RBASIC_SET_SHAPE_ID(dest, dest_shape_id);
367367
}
368368

369369
static void

0 commit comments

Comments
 (0)