10000 Get rid of SHAPE_T_OBJECT · ruby/ruby@12d60fd · GitHub
[go: up one dir, main page]

Skip to content

Commit 12d60fd

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 4e39580 commit 12d60fd

File tree

10 files changed

+206
-161
lines changed

10 files changed

+206
-161
lines changed

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
@@ -379,19 +379,7 @@ rb_gc_set_shape(VALUE obj, uint32_t shape_id)
379379
uint32_t
380380
rb_gc_rebuild_shape(VALUE obj, size_t heap_id)
381381
{
382-
shape_id_t orig_shape_id = rb_obj_shape_id(obj);
383-
if (rb_shape_too_complex_p(orig_shape_id)) {
384-
return (uint32_t)orig_shape_id;
385-
}
386-
387-
shape_id_t initial_shape_id = rb_shape_root(heap_id);
388-
shape_id_t new_shape_id = rb_shape_traverse_from_new_root(initial_shape_id, orig_shape_id);
389-
390-
if (new_shape_id == INVALID_SHAPE_ID) {
391-
return 0;
392-
}
393-
394-
return (uint32_t)new_shape_id;
382+
return (uint32_t)rb_shape_transition_heap(obj, heap_id);
395383
}
396384

397385
void rb_vm_update_references(void *ptr);
@@ -1923,6 +1911,7 @@ object_id0(VALUE obj)
19231911
// rb_shape_object_id_shape may lock if the current shape has
19241912
// multiple children.
19251913
shape_id_t object_id_shape_id = rb_shape_transition_object_id(obj);
1914+
RUBY_ASSERT(rb_shape_has_object_id(object_id_shape_id));
19261915

19271916
id = generate_next_object_id();
19281917
rb_obj_field_set(obj, object_id_shape_id, id);

object.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,17 +339,16 @@ 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-
if (RSHAPE(initial_shape_id)->heap_index != RSHAPE(src_shape_id)->heap_index || !rb_shape_canonical_p(src_shape_id)) {
343-
RUBY_ASSERT(RSHAPE(initial_shape_id)->type == SHAPE_T_OBJECT);
342+
RUBY_ASSERT(RSHAPE(initial_shape_id)->type == SHAPE_ROOT);
344343

345-
dest_shape_id = rb_shape_rebuild(initial_shape_id, src_shape_id);
346-
if (UNLIKELY(rb_shape_too_complex_p(dest_shape_id))) {
347-
st_table *table = rb_st_init_numtable_with_size(src_num_ivs);
348-
rb_obj_copy_ivs_to_hash_table(obj, table);
349-
rb_obj_init_too_complex(dest, table);
344+
dest_shape_id = rb_shape_rebuild(initial_shape_id, src_shape_id);
350345

351-
return;
352-
}
346+
if (UNLIKELY(rb_shape_too_complex_p(dest_shape_id))) {
347+
st_table *table = rb_st_init_numtable_with_size(src_num_ivs);
348+
rb_obj_copy_ivs_to_hash_table(obj, table);
349+
rb_obj_init_too_complex(dest, table);
350+
351+
return;
353352
}
354353

355354
VALUE *src_buf = ROBJECT_FIELDS(obj);
@@ -365,7 +364,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
365364
}
366365

367366
rb_shape_copy_fields(dest, dest_buf, dest_shape_id, obj, src_buf, src_shape_id);
368-
rb_obj_set_shape_id(dest, dest_shape_id);
367+
RBASIC_SET_SHAPE_ID(dest, dest_shape_id);
369368
}
370369

371370
static void

proc.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,8 @@ rb_binding_alloc(VALUE klass)
298298
return obj;
299299
}
300300

301-
302-
/* :nodoc: */
303301
static VALUE
304-
binding_dup(VALUE self)
302+
binding_copy(VALUE self)
305303
{
306304
VALUE bindval = rb_binding_alloc(rb_cBinding);
307305
rb_binding_t *src, *dst;
@@ -310,15 +308,21 @@ binding_dup(VALUE self)
310308
rb_vm_block_copy(bindval, &dst->block, &src->block);
311309
RB_OBJ_WRITE(bindval, &dst->pathobj, src->pathobj);
312310
dst->first_lineno = src->first_lineno;
313-
return rb_obj_dup_setup(self, bindval);
311+
return bindval;
312+
}
313+
314+
/* :nodoc: */
315+
static VALUE
316+
binding_dup(VALUE self)
317+
{
318+
return rb_obj_dup_setup(self, binding_copy(self));
314319
}
315320

316321
/* :nodoc: */
317322
static VALUE
318323
binding_clone(VALUE self)
319324
{
320-
VALUE bindval = binding_dup(self);
321-
return rb_obj_clone_setup(self, bindval, Qnil);
325+
return rb_obj_clone_setup(self, binding_copy(self), Qnil);
322326
}
323327

324328
VALUE

0 commit comments

Comments
 (0)
0