summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-07-20 15:30:19 -0400
committerPeter Zhu <peter@peterzhu.ca>2022-07-21 09:02:45 -0400
commit1c9acb6bb1822f9d914b40dcea0b3ead849165cd (patch)
tree87455306e2093eb41b2d7a48ea69edd508f4c882 /internal
parent4798a4fec213ce8a73a2d0d1c4ba879fb216ca3a (diff)
Refactor macros of array.c
Move some macros in array.c to internal/array.h so that other files can also access these macros.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6157
Diffstat (limited to 'internal')
-rw-r--r--internal/array.h55
1 files changed, 54 insertions, 1 deletions
diff --git a/internal/array.h b/internal/array.h
index aa3b540153..0c8ad3f3d6 100644
--- a/internal/array.h
+++ b/internal/array.h
@@ -18,7 +18,9 @@
# define ARRAY_DEBUG (0+RUBY_DEBUG)
#endif
-#define RARRAY_PTR_IN_USE_FLAG FL_USER14
+#define RARRAY_SHARED_ROOT_FLAG FL_USER12
+#define RARRAY_PTR_IN_USE_FLAG FL_USER14
+#define RARRAY_LITERAL_FLAG FL_USER15
/* array.c */
VALUE rb_ary_last(int, const VALUE *, VALUE);
@@ -73,6 +75,57 @@ ARY_PTR_USING_P(VALUE ary)
return FL_TEST_RAW(ary, RARRAY_PTR_IN_USE_FLAG);
}
+RBIMPL_ATTR_MAYBE_UNUSED()
+static inline int
+ary_should_not_be_shared_and_embedded(VALUE ary)
+{
+ return !FL_ALL_RAW(ary, ELTS_SHARED|RARRAY_EMBED_FLAG);
+}
+
+static inline bool
+ARY_SHARED_P(VALUE ary)
+{
+ assert(RB_TYPE_P(ary, T_ARRAY));
+ assert(ary_should_not_be_shared_and_embedded(ary));
+ return FL_TEST_RAW(ary, ELTS_SHARED);
+}
+
+static inline bool
+ARY_EMBED_P(VALUE ary)
+{
+ assert(RB_TYPE_P(ary, T_ARRAY));
+ assert(ary_should_not_be_shared_and_embedded(ary));
+ return FL_TEST_RAW(ary, RARRAY_EMBED_FLAG);
+}
+
+static inline VALUE
+ARY_SHARED_ROOT(VALUE ary)
+{
+ assert(ARY_SHARED_P(ary));
+ return RARRAY(ary)->as.heap.aux.shared_root;
+}
+
+static inline bool
+ARY_SHARED_ROOT_P(VALUE ary)
+{
+ assert(RB_TYPE_P(ary, T_ARRAY));
+ return FL_TEST_RAW(ary, RARRAY_SHARED_ROOT_FLAG);
+}
+
+static inline long
+ARY_SHARED_ROOT_REFCNT(VALUE ary)
+{
+ assert(ARY_SHARED_ROOT_P(ary));
+ return RARRAY(ary)->as.heap.aux.capa;
+}
+
+static inline bool
+ARY_LITERAL_P(VALUE ary)
+{
+ assert(RB_TYPE_P(ary, T_ARRAY));
+ return FL_TEST_RAW(ary, RARRAY_LITERAL_FLAG);
+}
+
static inline void
RARY_TRANSIENT_SET(VALUE ary)
{