summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2022-11-08 14:09:43 -0500
committerPeter Zhu <peter@peterzhu.ca>2022-11-10 10:11:34 -0500
commitc726c48a3dacd9ca1cb0d96fee98890cb74b37d3 (patch)
treef2bbd9f9797ee63e8666fffd18c47e04571b7a6f /variable.c
parent5246f4027ec574e77809845e1b1f7822cc2a5cef (diff)
downloadruby-c726c48a3dacd9ca1cb0d96fee98890cb74b37d3.tar.gz
Remove numiv from RObject
Since object shapes store the capacity of an object, we no longer need the numiv field on RObjects. This gives us one extra slot which we can use to give embedded objects one more instance variable (for a total of 3 ivs). This commit removes the concept of numiv from RObject.
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/variable.c b/variable.c
index bdde4d9607..2fed1e3512 100644
--- a/variable.c
+++ b/variable.c
@@ -1346,7 +1346,7 @@ rb_obj_transient_heap_evacuate(VALUE obj, int promote)
if (ROBJ_TRANSIENT_P(obj)) {
assert(!RB_FL_TEST_RAW(obj, ROBJECT_EMBED));
- uint32_t len = ROBJECT_NUMIV(obj);
+ uint32_t len = ROBJECT_IV_CAPACITY(obj);
const VALUE *old_ptr = ROBJECT_IVPTR(obj);
VALUE *new_ptr;
@@ -1378,7 +1378,6 @@ rb_ensure_iv_list_size(VALUE obj, uint32_t current_capacity, uint32_t new_capaci
else {
newptr = obj_ivar_heap_realloc(obj, current_capacity, new_capacity);
}
- ROBJECT_SET_NUMIV(obj, new_capacity);
}
struct gen_ivtbl *
@@ -1405,21 +1404,14 @@ rb_ensure_generic_iv_list_size(VALUE obj, uint32_t newsize)
rb_shape_t *
rb_grow_iv_list(VALUE obj)
{
- uint32_t len = ROBJECT_NUMIV(obj);
+ rb_shape_t * initial_shape = rb_shape_get_shape(obj);
+ uint32_t len = initial_shape->capacity;
RUBY_ASSERT(len > 0);
uint32_t newsize = (uint32_t)(len * 2);
rb_ensure_iv_list_size(obj, len, newsize);
- rb_shape_t * res;
-#if USE_RVARGC
- ROBJECT_SET_NUMIV(obj, newsize);
-#else
- ROBJECT(obj)->as.heap.numiv = newsize;
-#endif
-
- res = rb_shape_transition_shape_capa(rb_shape_get_shape(obj), newsize);
+ rb_shape_t * res = rb_shape_transition_shape_capa(initial_shape, newsize);
rb_shape_set_shape(obj, res);
- RUBY_ASSERT(!RB_TYPE_P(obj, T_OBJECT) || ROBJECT_IV_CAPACITY(obj) == ROBJECT_NUMIV(obj));
return res;
}
@@ -1437,12 +1429,10 @@ obj_ivar_set(VALUE obj, ID id, VALUE val)
found = false;
}
- uint32_t len = ROBJECT_NUMIV(obj);
-
// Reallocating can kick off GC. We can't set the new shape
// on this object until the buffer has been allocated, otherwise
// GC could read off the end of the buffer.
- if (len <= index) {
+ if (shape->capacity <= index) {
shape = rb_grow_iv_list(obj);
}