diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-07 06:41:32 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-07 06:41:32 +0000 |
commit | 030ff85a1f03f41aec164c3c3d4bdbbabe220a43 (patch) | |
tree | 4da19d177860b3f3e90d8cf575c69a0397c1c9b3 /internal.h | |
parent | 655e354e1acb81179239a637bba053733483fbe0 (diff) | |
download | ruby-030ff85a1f03f41aec164c3c3d4bdbbabe220a43.tar.gz |
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.h | 15 |
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 |