This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Allow regexp-to-pvlv assignment
authorFather Chrysostomos <sprout@cpan.org>
Tue, 30 Oct 2012 16:44:26 +0000 (09:44 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 30 Oct 2012 19:36:45 +0000 (12:36 -0700)
commit8d919b0a35f2b57a6bed2f8355b25b19ac5ad0c5
treedeaa4e227975359d48e1f5270ed0a82c53287875
parentf3cb5c3120c59ad2b1843ec808acee239bae8250
Allow regexp-to-pvlv assignment

Since the xpvlv and regexp structs conflict, we have to find somewhere
else to put the regexp struct.

I was going to sneak it in SvPVX, allocating a buffer large
enough to fit the regexp struct followed by the string, and have
SvPVX - sizeof(regexp) point to the struct.  But that would make all
regexp flag-checking macros fatter, and those are used in hot code.

So I came up with another method.  Regexp stringification is not
speed-critical.  So we can move the regexp stringification out of
re->sv_u and put it in the regexp struct.  Then the regexp struct
itself can be pointed to by re->sv_u.  So SVt_REGEXPs will have
re->sv_any and re->sv_u pointing to the same spot.  PVLVs can then
have sv->sv_any point to the xpvlv body as usual, but have sv->sv_u
point to a regexp struct.  All regexp member access can go through
sv_u instead of sv_any, which will be no slower than before.

Regular expressions will no longer be SvPOK, so we give sv_2pv spec-
ial logic for regexps.  We don’t need to make the regexp struct
larger, as SvLEN is currently always 0 iff mother_re is set.  So we
can replace the SvLEN field with the pv.

SvFAKE is never used without SvPOK or SvSCREAM also set.  So we can
use that to identify regexps.
16 files changed:
dump.c
ext/B/B.xs
ext/B/B/Concise.pm
ext/Devel-Peek/t/Peek.t
inline.h
op.c
perl.h
pp_ctl.c
pp_hot.c
regcomp.c
regcomp.h
regexec.c
regexp.h
sv.c
sv.h
t/op/qr.t