From 030ff85a1f03f41aec164c3c3d4bdbbabe220a43 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 7 Apr 2017 06:41:32 +0000 Subject: 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 --- internal.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'internal.h') 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 -- cgit v1.2.3