aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2020-08-26 00:07:08 -0700
committerPaul Eggert2020-08-26 00:20:31 -0700
commit768bea30cbc0a5e7851fa60ad1ea7ec14cf2cdd8 (patch)
treef21a0af8dddb6376f460593c85b31628afb320ba /src
parent438975bbaa25b7de74993e7928c45cf5779442b8 (diff)
downloademacs-768bea30cbc0a5e7851fa60ad1ea7ec14cf2cdd8.tar.gz
emacs-768bea30cbc0a5e7851fa60ad1ea7ec14cf2cdd8.zip
regex-emacs omit allocation of 3 slots
* src/regex-emacs.c (re_match_2_internal): Avoid unnecessary allocation of REGEND[0], BEST_REGSTART[0], BEST_REGEND[0].
Diffstat (limited to 'src')
-rw-r--r--src/regex-emacs.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/regex-emacs.c b/src/regex-emacs.c
index 954a193371a..da73f58f503 100644
--- a/src/regex-emacs.c
+++ b/src/regex-emacs.c
@@ -3923,8 +3923,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
3923 attempt) by a subexpression part of the pattern, that is, the 3923 attempt) by a subexpression part of the pattern, that is, the
3924 regnum-th regstart pointer points to where in the pattern we began 3924 regnum-th regstart pointer points to where in the pattern we began
3925 matching and the regnum-th regend points to right after where we 3925 matching and the regnum-th regend points to right after where we
3926 stopped matching the regnum-th subexpression. (The zeroth register 3926 stopped matching the regnum-th subexpression. */
3927 keeps track of what the whole pattern matches.) */
3928 re_char **regstart UNINIT, **regend UNINIT; 3927 re_char **regstart UNINIT, **regend UNINIT;
3929 3928
3930 /* The following record the register info as found in the above 3929 /* The following record the register info as found in the above
@@ -3973,20 +3972,21 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
3973 /* Do not bother to initialize all the register variables if there are 3972 /* Do not bother to initialize all the register variables if there are
3974 no groups in the pattern, as it takes a fair amount of time. If 3973 no groups in the pattern, as it takes a fair amount of time. If
3975 there are groups, we include space for register 0 (the whole 3974 there are groups, we include space for register 0 (the whole
3976 pattern), even though we never use it, since it simplifies the 3975 pattern) in REGSTART[0], even though we never use it, to avoid
3977 array indexing. We should fix this. */ 3976 the undefined behavior of subtracting 1 from REGSTART. */
3978 if (bufp->re_nsub) 3977 ptrdiff_t re_nsub = num_regs - 1;
3978 if (0 < re_nsub)
3979 { 3979 {
3980 regstart = SAFE_ALLOCA (num_regs * 4 * sizeof *regstart); 3980 regstart = SAFE_ALLOCA ((re_nsub * 4 + 1) * sizeof *regstart);
3981 regend = regstart + num_regs; 3981 regend = regstart + num_regs;
3982 best_regstart = regend + num_regs; 3982 best_regstart = regend + re_nsub;
3983 best_regend = best_regstart + num_regs; 3983 best_regend = best_regstart + re_nsub;
3984 }
3985 3984
3986 /* Initialize subexpression text positions to -1 to mark ones that no 3985 /* Initialize subexpression text positions to unset, to mark ones
3987 start_memory/stop_memory has been seen for. */ 3986 that no start_memory/stop_memory has been seen for. */
3988 for (ptrdiff_t reg = 1; reg < num_regs; reg++) 3987 for (re_char **apos = regstart + 1; apos < best_regstart + 1; apos++)
3989 regstart[reg] = regend[reg] = NULL; 3988 *apos = NULL;
3989 }
3990 3990
3991 /* We move 'string1' into 'string2' if the latter's empty -- but not if 3991 /* We move 'string1' into 'string2' if the latter's empty -- but not if
3992 'string1' is null. */ 3992 'string1' is null. */