diff options
author | David Mitchell <davem@iabyn.com> | 2014-02-02 13:44:07 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2014-02-08 13:50:09 +0000 |
commit | 826b9972dca076598a5c28b611d681f45b586318 (patch) | |
tree | 00151b0e25cbcf30f701e6f31a5d856709b9a00c /regexec.c | |
parent | 7d4ad9f90baf4256bba3cc273851b52721d4074c (diff) | |
download | perl-826b9972dca076598a5c28b611d681f45b586318.tar.gz |
re_intuit_start(): reduce use of *_offset macros
There are a number of macros with definitions like
#define anchored_offset substrs->data[0].min_offset
#define float_min_offset substrs->data[1].min_offset
In the two "other substr" branches, replace uses of these macros, e.g.
{
...
foo = prog->float_min_offset;
...
}
with
{
struct reg_substr_datum *other = &prog->substrs->data[other_ix];
...
foo = other->min_offset;
...
}
As well as making debugging easier (a debugger might display real fields
but not macros), and potentially making the binary more compact and faster
(unless the compiler is clever enough to optimise away every use of the
'prog->substrs->data[0]' dereference), it also helps make the two "other
substr" branches more similar, bringing us closer to eventually merging
them.
Diffstat (limited to 'regexec.c')
-rw-r--r-- | regexec.c | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -920,6 +920,7 @@ Perl_re_intuit_start(pTHX_ char *last, *last1; char * const saved_s = s; SV* must; + struct reg_substr_datum *other = &prog->substrs->data[other_ix]; /* we've previously found a floating substr starting at s. * This means that the regex origin must lie somewhere @@ -931,19 +932,19 @@ Perl_re_intuit_start(pTHX_ * HOP3(max, anchored_offset) + SvCUR(substr) */ assert(strpos + start_shift <= s); - last = HOP4c(s, prog->anchored_offset-start_shift, + last = HOP4c(s, other->min_offset - start_shift, strbeg, strend); - s = HOP3c(rx_origin, prog->anchored_offset, strend); + s = HOP3c(rx_origin, other->min_offset, strend); if (s < other_last) /* These positions already checked */ s = other_last; - assert(prog->minlen > prog->anchored_offset); + assert(prog->minlen > other->min_offset); last1 = HOP3c(strend, - prog->anchored_offset-prog->minlen, strbeg); + other->min_offset - prog->minlen, strbeg); /* On end-of-str: see comment below. */ - must = utf8_target ? prog->anchored_utf8 : prog->anchored_substr; + must = utf8_target ? other->utf8_substr : other->substr; assert(SvPOK(must)); s = fbm_instr( (unsigned char*)s, @@ -970,13 +971,13 @@ Perl_re_intuit_start(pTHX_ ", trying floating at offset %ld...\n", (long)(HOP3c(saved_s, 1, strend) - i_strpos))); other_last = HOP3c(last, 1, strend); - rx_origin = HOP4c(last, 1 - prog->anchored_offset, strbeg, strend); + rx_origin = HOP4c(last, 1 - other->min_offset, strbeg, strend); goto restart; } else { DEBUG_EXECUTE_r(PerlIO_printf(Perl_debug_log, " at offset %ld...\n", (long)(s - i_strpos))); - rx_origin = HOP3c(s, -prog->anchored_offset, strbeg); + rx_origin = HOP3c(s, -other->min_offset, strbeg); other_last = HOP3c(s, 1, strend); s = saved_s; if (rx_origin == strpos) @@ -989,6 +990,7 @@ Perl_re_intuit_start(pTHX_ char *last, *last1; char * const saved_s = s; SV* must; + struct reg_substr_datum *other = &prog->substrs->data[other_ix]; /* Calculate last1, the absolute latest point where the * floating substr could start in the string, ignoring any @@ -1027,7 +1029,7 @@ Perl_re_intuit_start(pTHX_ * to CHR_SVLEN(must) - !!SvTAIL(must) + prog->float_end_shift */ last1 = - HOP3c(strend, -prog->minlen + prog->float_min_offset, strbeg); + HOP3c(strend, other->min_offset - prog->minlen, strbeg); /* last is the latest point where the floating substr could * start, *given* any constraints from the earlier fixed @@ -1045,16 +1047,16 @@ Perl_re_intuit_start(pTHX_ * it will be less than or equal to (last1 - rx_origin) * chars; meaning it errs towards doing the accurate HOP3 * rather than just using last1 as a short-cut */ - (last1 - rx_origin) < prog->float_max_offset + (last1 - rx_origin) < other->max_offset ? last1 - : (char*)HOP3lim(rx_origin, prog->float_max_offset, last1); + : (char*)HOP3lim(rx_origin, other->max_offset, last1); /* set s to the earliest position the float string can start */ - s = HOP3c(rx_origin, prog->float_min_offset, strend); + s = HOP3c(rx_origin, other->min_offset, strend); if (s < other_last) /* skip previous failures */ s = other_last; - must = utf8_target ? prog->float_utf8 : prog->float_substr; + must = utf8_target ? other->utf8_substr : other->substr; assert(SvPOK(must)); /* fbm_instr() takes into account exact value of end-of-str if the check is SvTAIL(ed). Since false positives are OK, |