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

Skip to content

Commit 76e9c04

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 2e0bca2 commit 76e9c04

File tree

15 files changed

+242
-181
lines changed

15 files changed

+242
-181
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);

internal/variable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ VALUE rb_gvar_get(ID);
7070
VALUE rb_gvar_set(ID, VALUE);
7171
VALUE rb_gvar_defined(ID);
7272
void rb_const_warn_if_deprecated(const rb_const_entry_t *, VALUE, ID);
73-
void rb_ensure_iv_list_size(VALUE obj, uint32_t len, uint32_t newsize);
73+
void rb_ensure_iv_list_size(VALUE obj, uint32_t current_len, uint32_t newsize);
7474
attr_index_t rb_obj_ivar_set(VALUE obj, ID id, VALUE val);
7575

7676
#endif /* INTERNAL_VARIABLE_H */

object.c

Lines changed: 10 additions & 12 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);
@@ -358,14 +357,13 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
358357
attr_index_t initial_capa = RSHAPE_CAPACITY(initial_shape_id);
359358
attr_index_t dest_capa = RSHAPE_CAPACITY(dest_shape_id);
360359

361-
RUBY_ASSERT(src_num_ivs <= initial_capa);
362360
if (initial_capa < dest_capa) {
363-
rb_ensure_iv_list_size(dest, initial_capa, dest_capa);
361+
rb_ensure_iv_list_size(dest, 0, dest_capa);
364362
dest_buf = ROBJECT_FIELDS(dest);
365363
}
366364

367365
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);
366+
RBASIC_SET_SHAPE_ID(dest, dest_shape_id);
369367
}
370368

371369
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