}
use OptreeCheck;
use Config;
-plan tests => 34;
+plan tests => 37;
pass("GENERAL OPTREE EXAMPLES");
# 6 <@> leave[1 ref] vKP/REFC
EONT_EONT
+pass("rpeep - return \$x at end of sub");
+
+checkOptree ( name => '-exec sub { return 1 }',
+ code => sub { return 1 },
+ bcopts => '-exec',
+ strip_open_hints => 1,
+ expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
+# 1 <;> nextstate(main 1 -e:1) v
+# 2 <$> const[IV 1] s
+# 3 <1> leavesub[1 ref] K/REFC,1
+EOT_EOT
+# 1 <;> nextstate(main 1 -e:1) v
+# 2 <$> const(IV 1) s
+# 3 <1> leavesub[1 ref] K/REFC,1
+EONT_EONT
+
__END__
#######################################################################
case OP_NEXTSTATE:
PL_curcop = ((COP*)o); /* for warnings */
+ /* Optimise a "return ..." at the end of a sub to just be "...".
+ * This saves 2 ops. Before:
+ * 1 <;> nextstate(main 1 -e:1) v ->2
+ * 4 <@> return K ->5
+ * 2 <0> pushmark s ->3
+ * - <1> ex-rv2sv sK/1 ->4
+ * 3 <#> gvsv[*cat] s ->4
+ *
+ * After:
+ * - <@> return K ->-
+ * - <0> pushmark s ->2
+ * - <1> ex-rv2sv sK/1 ->-
+ * 2 <$> gvsv(*cat) s ->3
+ */
+ {
+ OP *next = o->op_next;
+ OP *sibling = o->op_sibling;
+ if ( OP_TYPE_IS(next, OP_PUSHMARK)
+ && OP_TYPE_IS(sibling, OP_RETURN)
+ && OP_TYPE_IS(sibling->op_next, OP_LINESEQ)
+ && OP_TYPE_IS(sibling->op_next->op_next, OP_LEAVESUB)
+ && cUNOPx(sibling)->op_first == next
+ && next->op_sibling && next->op_sibling->op_next
+ && next->op_sibling->op_next == sibling
+ && next->op_next && sibling->op_next)
+ {
+ next->op_sibling->op_next = sibling->op_next;
+ o->op_next = next->op_next;
+ }
+ }
+
/* Two NEXTSTATEs in a row serve no purpose. Except if they happen
to carry two labels. For now, take the easier option, and skip
this optimisation if the first NEXTSTATE has a label. */
to the registree to ensure it is accurate. The value returned will be
one of the OA_* constants from op.h.
+=for apidoc Am|bool|OP_TYPE_IS|OP *o, Optype type
+Returns true if the given OP is not NULL and if it is of the given
+type.
=cut
*/
? XopENTRYCUSTOM(o, xop_class) \
: (PL_opargs[(o)->op_type] & OA_CLASS_MASK))
+#define OP_TYPE_IS(o, type) ((o) && (o)->op_type == (type))
+
+
#define newSUB(f, o, p, b) Perl_newATTRSUB(aTHX_ (f), (o), (p), NULL, (b))
#ifdef PERL_MAD