summaryrefslogtreecommitdiff
path: root/internal.h
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-07 06:41:32 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-04-07 06:41:32 +0000
commit7519688ed86cb8b423fd24d4e27964056e78bc9b (patch)
tree4da19d177860b3f3e90d8cf575c69a0397c1c9b3 /internal.h
parent5c79f6dbb7eed53bdd693adece7c28e422d71b53 (diff)
introduce imemo_type_p(v, imemo_type)
* internal.h: introduce imemo_type_p() which checks the given value is T_IMEMO and imemo_type() == given imemo_type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'internal.h')
-rw-r--r--internal.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal.h b/internal.h
index 993b0266ed..c87d087d0d 100644
--- a/internal.h
+++ b/internal.h
@@ -855,6 +855,21 @@ imemo_type(VALUE imemo)
return (RBASIC(imemo)->flags >> FL_USHIFT) & imemo_mask;
}
+static inline int
+imemo_type_p(VALUE imemo, enum imemo_type imemo_type)
+{
+ if (LIKELY(!RB_SPECIAL_CONST_P(imemo))) {
+ /* fixed at compile time if imemo_type is given. */
+ const VALUE mask = (imemo_mask << FL_USHIFT) | RUBY_T_MASK;
+ const VALUE expected_type = (imemo_type << FL_USHIFT) | T_IMEMO;
+ /* fixed at runtime. */
+ return expected_type == (RBASIC(imemo)->flags & mask);
+ }
+ else {
+ return 0;
+ }
+}
+
/* FL_USER0 to FL_USER2 is for type */
#define IMEMO_FL_USHIFT (FL_USHIFT + 3)
#define IMEMO_FL_USER0 FL_USER3