This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge all B::OP::* accessors returning B::OP objects.
authorNicholas Clark <nick@ccl4.org>
Wed, 27 Oct 2010 15:27:27 +0000 (16:27 +0100)
committerNicholas Clark <nick@ccl4.org>
Fri, 29 Oct 2010 14:28:08 +0000 (15:28 +0100)
Use the ALIAS value to store the member's offset within the structure, and
perform explicit pointer arithmetic to read it. This reduces the object size
by about 5K on this platform.

ext/B/B.xs

index c0c9a4a..d706829 100644 (file)
@@ -831,12 +831,25 @@ threadsv_names()
 # endif
 #endif
 
-#define OP_next(o)     o->op_next
-#define OP_sibling(o)  o->op_sibling
 #define OP_targ(o)     o->op_targ
 #define OP_flags(o)    o->op_flags
 #define OP_private(o)  o->op_private
 
+#define OP_next_offset                 offsetof(struct op, op_next)
+#define OP_sibling_offset              offsetof(struct op, op_sibling)
+#define UNOP_first_offset              offsetof(struct unop, op_first)
+#define BINOP_last_offset              offsetof(struct binop, op_last)
+#define LOGOP_other_offset             offsetof(struct logop, op_other)
+#if PERL_VERSION >= 9
+#  define PMOP_pmreplstart_offset \
+       offsetof(struct pmop, op_pmstashstartu.op_pmreplstart)
+#else
+#  define PMOP_pmreplstart_offset      offsetof(struct pmop, op_pmreplstart)
+#endif
+#define LOOP_redoop_offset             offsetof(struct loop, op_redoop)
+#define LOOP_nextop_offset             offsetof(struct loop, op_nextop)
+#define LOOP_lastop_offset             offsetof(struct loop, op_lastop)
+
 MODULE = B     PACKAGE = B::OP         PREFIX = OP_
 
 size_t
@@ -847,13 +860,29 @@ OP_size(o)
     OUTPUT:
        RETVAL
 
+# The type checking code in B has always been identical for all OP types,
+# irrespective of whether the action is actually defined on that OP.
+# We should fix this
 B::OP
-OP_next(o)
-       B::OP           o
-
-B::OP
-OP_sibling(o)
+next(o)
        B::OP           o
+    ALIAS:
+       B::OP::next = OP_next_offset
+       B::OP::sibling = OP_sibling_offset
+       B::UNOP::first = UNOP_first_offset
+       B::BINOP::last = BINOP_last_offset
+       B::LOGOP::other = LOGOP_other_offset
+       B::PMOP::pmreplstart = PMOP_pmreplstart_offset
+       B::LOOP::redoop = LOOP_redoop_offset
+       B::LOOP::nextop = LOOP_nextop_offset
+       B::LOOP::lastop = LOOP_lastop_offset
+    PREINIT:
+       char *ptr;
+    CODE:
+       ptr = ix + (char *)o;
+       RETVAL = *((OP **)ptr);
+    OUTPUT:
+       RETVAL
 
 char *
 OP_name(o)
@@ -938,30 +967,6 @@ OP_oplist(o)
     PPCODE:
        SP = oplist(aTHX_ o, SP);
 
-#define UNOP_first(o)  o->op_first
-
-MODULE = B     PACKAGE = B::UNOP               PREFIX = UNOP_
-
-B::OP 
-UNOP_first(o)
-       B::UNOP o
-
-#define BINOP_last(o)  o->op_last
-
-MODULE = B     PACKAGE = B::BINOP              PREFIX = BINOP_
-
-B::OP
-BINOP_last(o)
-       B::BINOP        o
-
-#define LOGOP_other(o) o->op_other
-
-MODULE = B     PACKAGE = B::LOGOP              PREFIX = LOGOP_
-
-B::OP
-LOGOP_other(o)
-       B::LOGOP        o
-
 MODULE = B     PACKAGE = B::LISTOP             PREFIX = LISTOP_
 
 U32
@@ -1035,10 +1040,6 @@ PMOP_pmreplroot(o)
 
 #endif
 
-B::OP
-PMOP_pmreplstart(o)
-       B::PMOP         o
-
 #if PERL_VERSION < 9
 #define PMOP_pmnext(o)         o->op_pmnext
 
@@ -1163,25 +1164,6 @@ PVOP_pv(o)
        else
            ST(0) = newSVpvn_flags(o->op_pv, strlen(o->op_pv), SVs_TEMP);
 
-#define LOOP_redoop(o) o->op_redoop
-#define LOOP_nextop(o) o->op_nextop
-#define LOOP_lastop(o) o->op_lastop
-
-MODULE = B     PACKAGE = B::LOOP               PREFIX = LOOP_
-
-
-B::OP
-LOOP_redoop(o)
-       B::LOOP o
-
-B::OP
-LOOP_nextop(o)
-       B::LOOP o
-
-B::OP
-LOOP_lastop(o)
-       B::LOOP o
-
 #define COP_label(o)   CopLABEL(o)
 #define COP_stashpv(o) CopSTASHPV(o)
 #define COP_stash(o)   CopSTASH(o)