summaryrefslogtreecommitdiff
path: root/mg.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2009-05-21 08:08:53 +0200
committerNicholas Clark <nick@ccl4.org>2009-05-21 08:12:33 +0200
commit708854f2ff3eebc1ddfd657353b5092eae729cb8 (patch)
treebbf1652c9d4bd5f01fc9ee5aa4e9f19be1457f13 /mg.c
parent8ac77ac96d51ab94f305d02883edecb1e2a49e19 (diff)
downloadperl-708854f2ff3eebc1ddfd657353b5092eae729cb8.tar.gz
Cache the signal number or -1 in mg_private, to reduce calls to Perl_whichsig().
It doesn't matter that 0 isn't cacheable, as the logic in Perl_magic_setsig() is such that we already can't "set" $SIG{ZERO}. Without this we make thousands of failing calls to Perl_whichsig() from Perl_magic_getsig() for "__WARN__".
Diffstat (limited to 'mg.c')
-rw-r--r--mg.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/mg.c b/mg.c
index 75fee707d2..43fd7ba894 100644
--- a/mg.c
+++ b/mg.c
@@ -1237,10 +1237,14 @@ Perl_magic_getsig(pTHX_ SV *sv, MAGIC *mg)
{
dVAR;
/* Are we fetching a signal entry? */
- const I32 i = whichsig(MgPV_nolen_const(mg));
+ int i = (I16)mg->mg_private;
PERL_ARGS_ASSERT_MAGIC_GETSIG;
+ if (!i) {
+ mg->mg_private = i = whichsig(MgPV_nolen_const(mg));
+ }
+
if (i > 0) {
if(PL_psig_ptr[i])
sv_setsv(sv,PL_psig_ptr[i]);
@@ -1416,7 +1420,10 @@ Perl_magic_setsig(pTHX_ SV *sv, MAGIC *mg)
}
}
else {
- i = whichsig(s); /* ...no, a brick */
+ i = (I16)mg->mg_private;
+ if (!i) {
+ mg->mg_private = i = whichsig(s); /* ...no, a brick */
+ }
if (i <= 0) {
if (sv && ckWARN(WARN_SIGNAL))
Perl_warner(aTHX_ packWARN(WARN_SIGNAL), "No such signal: SIG%s", s);