regexec_flags(): simplify length calculation
authorDavid Mitchell <davem@iabyn.com>
Fri, 22 Jun 2012 15:26:08 +0000 (16:26 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sat, 8 Sep 2012 14:42:06 +0000 (15:42 +0100)
The code to calculate the length of the string to copy was

    PL_regeol - startpos + (stringarg - strbeg);

This is a hangover from the original (perl 3) regexp implementation
that under //i, copied and folded the original buffer: so startpos might
not equal stringarg. These days it always is (except under a match failure
with (*COMMIT), and the code we're interested is only executed on success).

So simplify to just PL_regeol - strbeg.

regexec.c

index 9db9577..df815b2 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -2568,7 +2568,7 @@ got_it:
     if ( !(flags & REXEC_NOT_FIRST) ) {
        RX_MATCH_COPY_FREE(rx);
        if (flags & REXEC_COPY_STR) {
-           const I32 i = PL_regeol - startpos + (stringarg - strbeg);
+           const I32 i = PL_regeol - strbeg;
 #ifdef PERL_OLD_COPY_ON_WRITE
            if ((SvIsCOW(sv)
                 || (SvFLAGS(sv) & CAN_COW_MASK) == CAN_COW_FLAGS)) {