ANYOF regnode often overallocates space
authorKarl Williamson <public@khwilliamson.com>
Tue, 26 Oct 2010 19:14:12 +0000 (13:14 -0600)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 27 Oct 2010 01:10:39 +0000 (18:10 -0700)
commit2c63ecadcb2533b7a53efa836736d86cb484d969
tree1bd78a70454feca4da3d354ebf01a416d8d91663
parent021897e0cddffa1615b83551abd2136c5f0fbeee
ANYOF regnode often overallocates space

The ANYOF regnode is used for [bracketed character classes].  It is
normally a struct regnode_charclass, but sometimes it is a struct
regnode_charclass_class, which adds an extra 4 bytes at the end to store
which of things like \d, \w, [:posix:] within the outer bracketed class
are to be matched at run time, like [\d\s[:upper:]].

However these are currently only stored the if the match is to be locale
based.  I haven't looked in the history, but the comments seem to
indicate that in the past those things were stored there all the time.

But, the space is allocated even if nothing gets stored there.  This
patch only allocates the space if there is one of these classes
occurring in a [bracketed class] and something is stored there, namely
only if the regex is being compiled under 'use locale'.

The previous code was not noting that these classes matched code points
(in the 'stored' variable), but was relying on ANYOF_LARGE getting set
which thus avoided it thinking it was a single character class that
could be optimized to an EXACT node.  Thus, this patch has to explicitly
set 'stored' to > 1, as the function already does elsewhere for similar
reasons.
regcomp.c