This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Faster feature checks
[perl5.git] / feature.h
index 3877e16..111c8a1 100644 (file)
--- a/feature.h
+++ b/feature.h
 
 #define HINT_FEATURE_SHIFT     26
 
+#define FEATURE_BITWISE_BIT         0x0001
+#define FEATURE___SUB___BIT         0x0002
+#define FEATURE_MYREF_BIT           0x0004
+#define FEATURE_EVALBYTES_BIT       0x0008
+#define FEATURE_FC_BIT              0x0010
+#define FEATURE_POSTDEREF_QQ_BIT    0x0020
+#define FEATURE_REFALIASING_BIT     0x0040
+#define FEATURE_SAY_BIT             0x0080
+#define FEATURE_SIGNATURES_BIT      0x0100
+#define FEATURE_STATE_BIT           0x0200
+#define FEATURE_SWITCH_BIT          0x0400
+#define FEATURE_UNIEVAL_BIT         0x0800
+#define FEATURE_UNICODE_BIT         0x1000
+
 #define FEATURE_BUNDLE_DEFAULT 0
 #define FEATURE_BUNDLE_510     1
 #define FEATURE_BUNDLE_511     2
        ((CURRENT_HINTS                                                  \
           & HINT_LOCALIZE_HH)                                            \
            ? Perl_feature_is_enabled(aTHX_ STR_WITH_LEN(name)) : FALSE)
+
+#define FEATURE_IS_ENABLED_MASK(mask)                   \
+  ((CURRENT_HINTS & HINT_LOCALIZE_HH)                \
+    ? (PL_curcop->cop_features & (mask)) : FALSE)
+
 /* The longest string we pass in.  */
 #define MAX_FEATURE_LEN (sizeof("postderef_qq")-1)
 
@@ -39,7 +58,7 @@
        (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
         CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("fc")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
     )
 
 #define FEATURE_SAY_IS_ENABLED \
@@ -47,7 +66,7 @@
        (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
         CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("say")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
     )
 
 #define FEATURE_STATE_IS_ENABLED \
@@ -55,7 +74,7 @@
        (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
         CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("state")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \
     )
 
 #define FEATURE_SWITCH_IS_ENABLED \
        (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
         CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("switch")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE_SWITCH_BIT)) \
     )
 
 #define FEATURE_BITWISE_IS_ENABLED \
     ( \
        CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("bitwise")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
     )
 
 #define FEATURE_EVALBYTES_IS_ENABLED \
        (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
         CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("evalbytes")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
     )
 
 #define FEATURE_SIGNATURES_IS_ENABLED \
     ( \
        CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("signatures") \
+        FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
     )
 
 #define FEATURE___SUB___IS_ENABLED \
        (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
         CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("__SUB__")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
     )
 
 #define FEATURE_REFALIASING_IS_ENABLED \
     ( \
        CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("refaliasing") \
+        FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
     )
 
 #define FEATURE_POSTDEREF_QQ_IS_ENABLED \
        (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
         CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("postderef_qq")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
     )
 
 #define FEATURE_UNIEVAL_IS_ENABLED \
        (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
         CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("unieval")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
     )
 
 #define FEATURE_MYREF_IS_ENABLED \
     ( \
        CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("myref") \
+        FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
     )
 
 #define FEATURE_UNICODE_IS_ENABLED \
        (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
         CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
      || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
-        FEATURE_IS_ENABLED("unicode")) \
+        FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
     )
 
 
+#define SAVEFEATUREBITS() SAVEI32(PL_compiling.cop_features)
+
+#define CLEARFEATUREBITS() (PL_compiling.cop_features = 0)
+
+#define STOREFEATUREBITSHH(hh) \
+  (hv_stores((hh), "feature/bits", newSVuv(PL_compiling.cop_features)))
+
+#define FETCHFEATUREBITSHH(hh)                              \
+  STMT_START {                                              \
+      SV **fbsv = hv_fetchs((hh), "feature/bits", FALSE);   \
+      PL_compiling.cop_features = fbsv ? SvUV(*fbsv) : 0;   \
+  } STMT_END
+
 #endif /* PERL_CORE or PERL_EXT */
 
 #ifdef PERL_IN_OP_C