summaryrefslogtreecommitdiff
path: root/shape.h
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2022-10-15 09:37:44 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2022-10-15 10:44:10 -0700
commitf0654b1027d2f24cbb6e3cfb0c5946b70f06739b (patch)
treee49476db3318c77362e7ad21433df7832f0ede95 /shape.h
parent8d20632df849833d8a98f3d6f5e61f32eefa0fa6 (diff)
downloadruby-f0654b1027d2f24cbb6e3cfb0c5946b70f06739b.tar.gz
More precisely iterate over Object instance variables
Shapes provides us with an (almost) exact count of instance variables. We only need to check for Qundef when an IV has been "undefined" Prefer to use ROBJECT_IV_COUNT when iterating IVs
Diffstat (limited to 'shape.h')
-rw-r--r--shape.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/shape.h b/shape.h
index c99fd1bfaa..e978bac121 100644
--- a/shape.h
+++ b/shape.h
@@ -125,6 +125,15 @@ bool rb_shape_get_iv_index(rb_shape_t * shape, ID id, attr_index_t * value);
shape_id_t rb_shape_id(rb_shape_t * shape);
MJIT_SYMBOL_EXPORT_END
+static inline uint32_t
+ROBJECT_IV_COUNT(VALUE obj)
+{
+ RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
+ uint32_t ivc = rb_shape_get_shape_by_id(ROBJECT_SHAPE_ID(obj))->iv_count;
+ RUBY_ASSERT(ivc <= ROBJECT_NUMIV(obj));
+ return ivc;
+}
+
rb_shape_t * rb_shape_alloc(ID edge_name, rb_shape_t * parent);
rb_shape_t * rb_shape_alloc_with_parent_id(ID edge_name, shape_id_t parent_id);