diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-03-08 20:01:46 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-03-08 21:32:36 +0000 |
commit | 63f281fa1e421520fab564bf3362bf3b7082b2c7 (patch) | |
tree | 8cec32f36409f4175ce12785aa6a0886a961f37c /ext/Tie-Hash-NamedCapture | |
parent | 6b3df22776523c7e117a080b445b166b31464123 (diff) | |
download | perl-63f281fa1e421520fab564bf3362bf3b7082b2c7.tar.gz |
Tweak Tie::Hash::NamedCapture's BOOT code - get the stash from the CV.
This will result in less work than using newSVrv(), as the character string
passed to that is used to walk the symbol table to find the stash. We already
have a fast way to get to the stash - via the CV's GV. So use that directly.
Diffstat (limited to 'ext/Tie-Hash-NamedCapture')
-rw-r--r-- | ext/Tie-Hash-NamedCapture/NamedCapture.xs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/ext/Tie-Hash-NamedCapture/NamedCapture.xs b/ext/Tie-Hash-NamedCapture/NamedCapture.xs index 459a9984f8..1956b50042 100644 --- a/ext/Tie-Hash-NamedCapture/NamedCapture.xs +++ b/ext/Tie-Hash-NamedCapture/NamedCapture.xs @@ -16,13 +16,15 @@ #define SCALAR_ALIAS (RXapif_SCALAR | (1 << EXPECT_SHIFT)) static -tie_it(pTHX_ const char name, UV flag) +tie_it(pTHX_ const char name, UV flag, HV *const stash) { GV *const gv = gv_fetchpvn(&name, 1, GV_ADDMULTI|GV_NOTQUAL, SVt_PVHV); HV *const hv = GvHV(gv); SV *rv = newSV_type(SVt_RV); - sv_setuv(newSVrv(rv, "Tie::Hash::NamedCapture"), flag); + SvRV_set(rv, newSVuv(flag)); + SvROK_on(rv); + sv_bless(rv, stash); sv_unmagic((SV *)hv, PERL_MAGIC_tied); sv_magic((SV *)hv, rv, PERL_MAGIC_tied, NULL, 0); @@ -33,8 +35,11 @@ MODULE = Tie::Hash::NamedCapture PACKAGE = Tie::Hash::NamedCapture PROTOTYPES: DISABLE BOOT: - tie_it(aTHX_ '-', RXapif_ALL); - tie_it(aTHX_ '+', RXapif_ONE); + { + HV *const stash = GvSTASH(CvGV(cv)); + tie_it(aTHX_ '-', RXapif_ALL, stash); + tie_it(aTHX_ '+', RXapif_ONE, stash); + } SV * TIEHASH(package, ...) |