regexec(): simplify RXf_ANCH_GPOS pos calc
authorDavid Mitchell <davem@iabyn.com>
Fri, 19 Jul 2013 16:10:04 +0000 (17:10 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sun, 28 Jul 2013 09:33:39 +0000 (10:33 +0100)
commit2f14ddcd0c64ac3c80bca49bad0af9734d9f6c6b
treef59f166ca860b37bb69bf3d94e521ae28ea835cc
parent3542935d7265972713626cf9f6a19e67554be369
regexec(): simplify RXf_ANCH_GPOS pos calc

There are two bits of code in regexec() that do special handling for
RXf_ANCH_GPOS:

First, after setting ganch from pos(), it does a couple of quick-fail
checks:
    fail if s > ganch
    fail if (ganch - gofs) < strbeg
at this point it also updates s to be ganch - gofs, although confusingly,
s in not subsequently used.

Second, when about to call regtry, it calculates a new  start value
(ignoring the old one, s):

    tmps_s = ganch - gofs;

then checks:
    fail if tmp_s < strbeg

As can be seen, these two sets of tests essentially partially duplicate
each other.

This commit moves all the work to the second block of code, which
simplifies things, and makes the first block of code purely about
calculating ganch.

Note that the new condition added by this commit in the second block,

    fail if s > tmp_s (i.e if s > (ganch - gofs))

subsumes both previous conditions, since
a) it is stronger than s > ganch
b) s will be >= strbeg, so tmp_s >= strbeg
regexec.c