Skip to content

Commit 2e0bca2

Browse files
committed
Refactor raw accesses to rb_shape_t.capacity
1 parent 0e0008d commit 2e0bca2

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

object.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,12 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
355355
VALUE *src_buf = ROBJECT_FIELDS(obj);
356356
VALUE *dest_buf = ROBJECT_FIELDS(dest);
357357

358-
RUBY_ASSERT(src_num_ivs <= RSHAPE(dest_shape_id)->capacity);
359-
if (RSHAPE(initial_shape_id)->capacity < RSHAPE(dest_shape_id)->capacity) {
360-
rb_ensure_iv_list_size(dest, RSHAPE(initial_shape_id)->capacity, RSHAPE(dest_shape_id)->capacity);
358+
attr_index_t initial_capa = RSHAPE_CAPACITY(initial_shape_id);
359+
attr_index_t dest_capa = RSHAPE_CAPACITY(dest_shape_id);
360+
361+
RUBY_ASSERT(src_num_ivs <= initial_capa);
362+
if (initial_capa < dest_capa) {
363+
rb_ensure_iv_list_size(dest, initial_capa, dest_capa);
361364
dest_buf = ROBJECT_FIELDS(dest);
362365
}
363366

shape.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ ROBJECT_FIELDS_CAPACITY(VALUE obj)
232232
// Asking for capacity doesn't make sense when the object is using
233233
// a hash table for storing instance variables
234234
RUBY_ASSERT(!rb_shape_obj_too_complex_p(obj));
235-
return RSHAPE(RBASIC_SHAPE_ID(obj))->capacity;
235+
return RSHAPE_CAPACITY(RBASIC_SHAPE_ID(obj));
236236
}
237237

238238
static inline st_table *

variable.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,13 +1825,13 @@ generic_fields_lookup_ensure_size(st_data_t *k, st_data_t *v, st_data_t u, int e
18251825
if (!existing || fields_lookup->resize) {
18261826
if (existing) {
18271827
RUBY_ASSERT(RSHAPE(fields_lookup->shape_id)->type == SHAPE_IVAR || RSHAPE(fields_lookup->shape_id)->type == SHAPE_OBJ_ID);
1828-
RUBY_ASSERT(RSHAPE(RSHAPE(fields_lookup->shape_id)->parent_id)->capacity < RSHAPE(fields_lookup->shape_id)->capacity);
1828+
RUBY_ASSERT(RSHAPE_CAPACITY(RSHAPE(fields_lookup->shape_id)->parent_id) < RSHAPE_CAPACITY(fields_lookup->shape_id));
18291829
}
18301830
else {
18311831
FL_SET_RAW((VALUE)*k, FL_EXIVAR);
18321832
}
18331833

1834-
fields_tbl = gen_fields_tbl_resize(fields_tbl, RSHAPE(fields_lookup->shape_id)->capacity);
1834+
fields_tbl = gen_fields_tbl_resize(fields_tbl, RSHAPE_CAPACITY(fields_lookup->shape_id));
18351835
*v = (st_data_t)fields_tbl;
18361836
}
18371837

@@ -2368,13 +2368,13 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
23682368
}
23692369
}
23702370

2371-
if (!RSHAPE(dest_shape_id)->capacity) {
2371+
if (!RSHAPE_LEN(dest_shape_id)) {
23722372
rb_obj_set_shape_id(dest, dest_shape_id);
23732373
FL_UNSET(dest, FL_EXIVAR);
23742374
return;
23752375
}
23762376

2377-
new_fields_tbl = gen_fields_tbl_resize(0, RSHAPE(dest_shape_id)->capacity);
2377+
new_fields_tbl = gen_fields_tbl_resize(0, RSHAPE_CAPACITY(dest_shape_id));
23782378

23792379
VALUE *src_buf = obj_fields_tbl->as.shape.fields;
23802380
VALUE *dest_buf = new_fields_tbl->as.shape.fields;

vm_insnhelper.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,8 +1458,8 @@ vm_setivar_default(VALUE obj, ID id, VALUE val, shape_id_t dest_shape_id, attr_i
14581458
rb_shape_t *shape = RSHAPE(shape_id);
14591459
rb_shape_t *dest_shape = RSHAPE(dest_shape_id);
14601460

1461-
if (shape_id == dest_shape->parent_id && dest_shape->edge_name == id && shape->capacity == dest_shape->capacity) {
1462-
RUBY_ASSERT(index < dest_shape->capacity);
1461+
if (shape_id == dest_shape->parent_id && dest_shape->edge_name == id && RSHAPE_CAPACITY(shape_id) == RSHAPE_CAPACITY(dest_shape_id)) {
1462+
RUBY_ASSERT(index < RSHAPE_CAPACITY(dest_shape_id));
14631463
}
14641464
else {
14651465
return Qundef;
@@ -1503,13 +1503,13 @@ vm_setivar(VALUE obj, ID id, VALUE val, shape_id_t dest_shape_id, attr_index_t i
15031503
rb_shape_t *dest_shape = RSHAPE(dest_shape_id);
15041504
shape_id_t source_shape_id = dest_shape->parent_id;
15051505

1506-
if (shape_id == source_shape_id && dest_shape->edge_name == id && shape->capacity == dest_shape->capacity) {
1506+
if (shape_id == source_shape_id && dest_shape->edge_name == id && RSHAPE_CAPACITY(shape_id) == RSHAPE_CAPACITY(dest_shape_id)) {
15071507
RUBY_ASSERT(dest_shape_id != INVALID_SHAPE_ID && shape_id != INVALID_SHAPE_ID);
15081508

15091509
RBASIC_SET_SHAPE_ID(obj, dest_shape_id);
15101510

15111511
RUBY_ASSERT(rb_shape_get_next_iv_shape(source_shape_id, id) == dest_shape_id);
1512-
RUBY_ASSERT(index < dest_shape->capacity);
1512+
RUBY_ASSERT(index < RSHAPE_CAPACITY(dest_shape_id));
15131513
}
15141514
else {
15151515
break;

0 commit comments

Comments
 (0)