aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2023-11-21 09:23:37 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2023-11-21 09:46:50 -0800
commit209a0253f5869678d7228731605a1a5f21c76f32 (patch)
tree5d78419fc1a7855c8243d23e57e8de295bcb6188 /variable.c
parentf397650cda4e99a8eaf710ac5bcf73da960dc30b (diff)
downloadruby-209a0253f5869678d7228731605a1a5f21c76f32.tar.gz
Use count macros for counting instance variables
We don't need to check for Qundef because the shape tells us the number if IVs that are stored on the object
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c35
1 files changed, 2 insertions, 33 deletions
diff --git a/variable.c b/variable.c
index f155f7e712..8151e55b85 100644
--- a/variable.c
+++ b/variable.c
@@ -2074,41 +2074,10 @@ rb_ivar_count(VALUE obj)
switch (BUILTIN_TYPE(obj)) {
case T_OBJECT:
- if (rb_shape_obj_too_complex(obj)) {
- return ROBJECT_IV_COUNT(obj);
- }
-
- if (rb_shape_get_shape(obj)->next_iv_index > 0) {
- st_index_t i, count, num = ROBJECT_IV_COUNT(obj);
- const VALUE *const ivptr = ROBJECT_IVPTR(obj);
- for (i = count = 0; i < num; ++i) {
- if (!UNDEF_P(ivptr[i])) {
- count++;
- }
- }
- return count;
- }
- break;
+ return ROBJECT_IV_COUNT(obj);
case T_CLASS:
case T_MODULE:
- if (rb_shape_get_shape(obj)->next_iv_index > 0) {
- st_index_t count = 0;
-
- RB_VM_LOCK_ENTER();
- {
- st_index_t i, num = rb_shape_get_shape(obj)->next_iv_index;
- const VALUE *const ivptr = RCLASS_IVPTR(obj);
- for (i = count = 0; i < num; ++i) {
- if (!UNDEF_P(ivptr[i])) {
- count++;
- }
- }
- }
- RB_VM_LOCK_LEAVE();
-
- return count;
- }
- break;
+ return RCLASS_IV_COUNT(obj);
default:
if (FL_TEST(obj, FL_EXIVAR)) {
struct gen_ivtbl *ivtbl;