summaryrefslogtreecommitdiff
path: root/shape.h
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2025-07-31 14:25:41 +0200
committerJean Boussier <jean.boussier@gmail.com>2025-07-31 21:55:51 +0200
commitf0c31c5e6492cfc088b8b87a9b86aeb75b22733d (patch)
treed4eafa889907c14b07c23a4715aeecd9438bcdf2 /shape.h
parent84ee71df4540c9c13854c86d6b30bf8f385780c8 (diff)
Get rid of RSHAPE_PARENT in favor of RSHAPE_DIRECT_CHILD_P
`RSHAPE_PARENT` is error prone because it returns a raw untagged shape_id. To check if a shape is a direct parent of another, tags should be discarded. So providing a comparison function is better than exposing untagged ids.
Diffstat (limited to 'shape.h')
-rw-r--r--shape.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/shape.h b/shape.h
index a418dc7821..2d13c9b762 100644
--- a/shape.h
+++ b/shape.h
@@ -271,11 +271,18 @@ rb_shape_root(size_t heap_id)
}
static inline shape_id_t
-RSHAPE_PARENT(shape_id_t shape_id)
+RSHAPE_PARENT_RAW_ID(shape_id_t shape_id)
{
return RSHAPE(shape_id)->parent_id;
}
+static inline bool
+RSHAPE_DIRECT_CHILD_P(shape_id_t parent_id, shape_id_t child_id)
+{
+ return (parent_id & SHAPE_ID_FLAGS_MASK) == (child_id & SHAPE_ID_FLAGS_MASK) &&
+ RSHAPE(child_id)->parent_id == (parent_id & SHAPE_ID_OFFSET_MASK);
+}
+
static inline enum shape_type
RSHAPE_TYPE(shape_id_t shape_id)
{