eliminate PL_reg_poscache, PL_reg_poscache_size
authorDavid Mitchell <davem@iabyn.com>
Fri, 31 May 2013 14:40:48 +0000 (15:40 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sun, 2 Jun 2013 21:28:54 +0000 (22:28 +0100)
commit2ac8ff4bf339d781f96fdfabd34d199a7f9569da
treeb3e85c2a06111db3d204bb623c99317985977873
parent331b2dcc3fd1fd971f7a6ed1192c36ceaa0d6a88
eliminate PL_reg_poscache, PL_reg_poscache_size

Eliminate these two global vars (well, fields in the global
PL_reg_state), that hold the regex super-liner cache.

PL_reg_poscache_size gets replaced with a field in the local regmatch_info
struct, while PL_reg_poscache (which needs freeing at end of pattern
execution or on croak()), goes in the regmatch_info_aux struct.

Note that this includes a slight change in behaviour.
Each regex execution now has its own private poscache pointer, initially
null.  If the super-linear behaviour is detected, the cache is malloced,
used for the duration of the pattern match, then freed.

The former behaviour allocated a global poscache on first use, which was
retained between regex executions. Since the poscache could between 0.25
and 2x the size of the string being matched, that could potentially be a
big buffer lying around unused. So we save memory at the expense of a new
malloc/free for every regex that triggers super-linear behaviour.

The old behaviour saved the old pointer on reentrancy, then restored the
old one (and possibly freed the new buffer) at exit. Except it didn't for
(?{}), so /(?{ m{something-that-triggers-super-linear-cache} })/ would
leak each time the inner regex was called. This is now fixed
automatically.
perl.c
regcomp.c
regexec.c
regexp.h
scope.c
sv.c