diff options
author | David Mitchell <davem@iabyn.com> | 2017-07-07 14:13:32 +0100 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2017-07-27 11:30:21 +0100 |
commit | df6b4bd56551f2d39f7c0019c23f27181d8c39c4 (patch) | |
tree | 760cb0b40c0f202fe06ae67e0a239156b92597fe /ext/B | |
parent | e8f01ee5fa8087b34dfe31b2c53eef0ba8718922 (diff) | |
download | perl-df6b4bd56551f2d39f7c0019c23f27181d8c39c4.tar.gz |
give REGEXP SVs the POK flag again
Commit v5.17.5-99-g8d919b0 stopped SVt_REGEXP SVs (and PVLVs acting as
regexes) from having the POK and pPOK flags set. This made things like
SvOK() and SvTRUE() slower, because as well as the quick single test for
any I/N/P/R flags, SvOK() also has to test for
(SvTYPE(sv) == SVt_REGEXP
|| (SvFLAGS(sv) & (SVTYPEMASK|SVp_POK|SVpgv_GP|SVf_FAKE))
== (SVt_PVLV|SVf_FAKE))
This commit fixes the issue fixed by g8d919b0 in a slightly different way,
which is less invasive and allows the POK flag.
Background:
PVLV are basically PVMGs with a few extra fields. They are intended to
be a superset of all scalar types, so any scalar value can be assigned
to a PVLV SV.
However, once REGEXPs were made into first-class scalar SVs, this
assumption broke - there are a whole bunch of fields in a regex SV body
which can't be copied to to a PVLV. So this broke:
sub f {
my $r = qr/abc/; # $r is reference to an SVt_REGEXP
$_[0] = $$r;
}
f($h{foo}); # the hash access is deferred - a temporary PVLV is
# passed instead
The basic idea behind the g8d919b0 fix was, for an LV-acting-as-regex,
to attach both a PVLV body and a regex body to the SV head. This commit
keeps this basic concept; it just changes how the extra body is attached.
The original fix changed SVt_REGEXP SVs so that sv.sv_u.svu_pv no longer
pointed to the regexp's string representation; instead this pointer was
stored in a union made out of the xpv_len field. Doing this necessitated
not turning the POK flag on for any REGEXP SVs.
This freed up the sv_u to point to the regex body, while the sv_any field
could continue to point to the PVLV body. An ReANY() macro was introduced
that returned the sv_u field rather than the sv_any field.
This commit changes it so that instead, on regexp SVs (and LV-as-regexp
SVs), sv_u always points to the string buffer (so they can have POK set
again), but on specifically LV-as-regex SVs, the xpv_len_u union of the
PVLV body points to the regexp body.
This means that SVt_REGEXP SVs are now completely "normal" again,
and SVt_PVLV SVs are normal except in the one case where they hold a
regex, in which case rather than storing the string buffer's length, the
PVLV body stores a pointer to the regex body.
Diffstat (limited to 'ext/B')
-rw-r--r-- | ext/B/B/Concise.pm | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/B/B/Concise.pm b/ext/B/B/Concise.pm index d877219190..6465a3c131 100644 --- a/ext/B/B/Concise.pm +++ b/ext/B/B/Concise.pm @@ -730,13 +730,13 @@ sub concise_sv { $hr->{svval} .= ["Null", "sv_undef", "sv_yes", "sv_no", '', '', '', "sv_zero"]->[$$sv]; } elsif ($preferpv - && ($sv->FLAGS & SVf_POK || class($sv) eq "REGEXP")) { + && ($sv->FLAGS & SVf_POK)) { $hr->{svval} .= cstring($sv->PV); } elsif ($sv->FLAGS & SVf_NOK) { $hr->{svval} .= $sv->NV; } elsif ($sv->FLAGS & SVf_IOK) { $hr->{svval} .= $sv->int_value; - } elsif ($sv->FLAGS & SVf_POK || class($sv) eq "REGEXP") { + } elsif ($sv->FLAGS & SVf_POK) { $hr->{svval} .= cstring($sv->PV); } elsif (class($sv) eq "HV") { $hr->{svval} .= 'HASH'; |