[Jifty-commit] r5584 - Runops-Trace/trunk

Jifty commits jifty-commit at lists.jifty.org
Sat Jul 26 13:33:42 EDT 2008


Author: nothingmuch
Date: Sat Jul 26 13:33:42 2008
New Revision: 5584

Modified:
   Runops-Trace/trunk/Trace.xs

Log:
opmask is bit vector, not bool array

Modified: Runops-Trace/trunk/Trace.xs
==============================================================================
--- Runops-Trace/trunk/Trace.xs	(original)
+++ Runops-Trace/trunk/Trace.xs	Sat Jul 26 13:33:42 2008
@@ -28,9 +28,9 @@
 STATIC UNOP Runops_Trace_fakeop;
 STATIC SV *Runops_Trace_fakeop_sv;
 
-/* op_type is 9 bits wide */
-#define OPMASK_SIZE (1 << 9) - 1
-STATIC bool *Runops_Trace_mask;
+#define MAXO_PLUS ( MAXO + 100 )
+#define MAXO_BIT_OCTETS ( ( MAXO_PLUS + 7 ) / 8 )
+STATIC char *Runops_Trace_mask;
 
 #define ARITY_NULL 0
 #define ARITY_UNARY 1
@@ -45,8 +45,8 @@
 {
   while (PL_op) {
     if ( Runops_Trace_enabled &&
-        /* if we have a mask set, only trace unmasked ops */
-        ( !Runops_Trace_mask || Runops_Trace_mask[PL_op->op_type] )
+        ( !Runops_Trace_mask /* trace if no mask */
+          || ( Runops_Trace_mask[PL_op->op_type >> 3] & ( 1 << (PL_op->op_type & 0x07) ) ) ) /* or this op is unmasked */
        ){
 
       /* the hook may have assigned PL_op itself, in which case we just go to
@@ -343,25 +343,31 @@
   Runops_Trace_threshold = t;
 }
 
-void
+STATIC void
+Runops_Trace_mask_set (bool t) {
+  if ( Runops_Trace_mask ) {
+    char *byte = Runops_Trace_mask;
+    while ( byte < Runops_Trace_mask + MAXO_BIT_OCTETS ) {
+      *byte++ = t ? 0xff : 0;
+    }
+  }
+}
+
+STATIC void
 Runops_Trace_mask_autocreate () {
   if (!Runops_Trace_mask) {
-    int i;
-    Newx(Runops_Trace_mask, OPMASK_SIZE, bool);
-    for (i = 0; i < OPMASK_SIZE; i++) {
-      Runops_Trace_mask[i] = 1;
-    }
+    I32 len = MAXO_BIT_OCTETS;
+
+    Newx(Runops_Trace_mask, MAXO_BIT_OCTETS, char);
+    Runops_Trace_mask_set(1);
   }
 }
 
 Runops_Trace_mask_all () {
   if (!Runops_Trace_mask) {
-    Newxz(Runops_Trace_mask, OPMASK_SIZE, bool);
+    Newxz(Runops_Trace_mask, MAXO_BIT_OCTETS, char);
   } else {
-    int i;
-    for (i = 0; i < OPMASK_SIZE; i++) {
-      Runops_Trace_mask[i] = 0;
-    }
+    Runops_Trace_mask_set(0);
   }
 }
 
@@ -369,18 +375,20 @@
   if (!Runops_Trace_mask) {
     Runops_Trace_mask_autocreate();
   } else {
-    int i;
-    for (i = 0; i < OPMASK_SIZE; i++) {
-      Runops_Trace_mask[i] = 1;
-    }
+    Runops_Trace_mask_set(1);
   }
 }
 
-void
-Runops_Trace_mask_set_op_type (unsigned op_type, bool bit) {
-  if ( op_type < OPMASK_SIZE ) {
-    Runops_Trace_mask_autocreate();
-    Runops_Trace_mask[op_type] = bit;
+STATIC void
+Runops_Trace_mask_set_op_type (I32 op_type, bool bit) {
+  if ( op_type < MAXO_PLUS && op_type >= 0 ) {
+    const int offset = op_type >> 3;
+    const int bit    = op_type & 0x07;
+
+    if (bit)
+      Runops_Trace_mask[offset] |=   1 << bit;
+    else
+      Runops_Trace_mask[offset] &= ~(1 << bit);
   } else {
     croak("Invalid op_type %d", op_type);
   }


More information about the Jifty-commit mailing list