This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sarathy's clear_pmop patch with Radu Greab's fix,
[perl5.git] / op.c
diff --git a/op.c b/op.c
index f721f06..25e7aa5 100644 (file)
--- a/op.c
+++ b/op.c
@@ -845,7 +845,7 @@ S_op_clear(pTHX_ OP *o)
 clear_pmop:
        {
            HV *pmstash = PmopSTASH(cPMOPo);
-           if (pmstash) {
+           if (pmstash && SvREFCNT(pmstash)) {
                PMOP *pmop = HvPMROOT(pmstash);
                PMOP *lastpmop = NULL;
                while (pmop) {
@@ -2763,7 +2763,7 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
            r = t; rlen = tlen; rend = tend;
        }
        if (!squash) {
-               if (t == r ||
+               if ((!rlen && !del) || t == r ||
                    (tlen == rlen && memEQ((char *)t, (char *)r, tlen)))
                {
                    o->op_private |= OPpTRANS_IDENTICAL;
@@ -2895,8 +2895,13 @@ Perl_pmtrans(pTHX_ OP *o, OP *expr, OP *repl)
                }
            }
        }
-       if (!del && (rlen > 0xff || tlen > 0xff)) {
-           if (j >= rlen)
+       if (!del) {
+           if (!rlen) {
+               j = rlen;
+               if (!squash)
+                   o->op_private |= OPpTRANS_IDENTICAL;
+           }
+           else if (j >= rlen)
                j = rlen - 1;
            else
                cPVOPo->op_pv = (char*)Renew(tbl, 0x101+rlen-j, short);