1 |
root |
1.1 |
#include "EXTERN.h" |
2 |
|
|
#include "perl.h" |
3 |
|
|
#include "XSUB.h" |
4 |
|
|
|
5 |
|
|
static OP *(*old_entersub)(pTHX); |
6 |
|
|
|
7 |
|
|
// this is, of course, a slower entersub |
8 |
|
|
static OP * |
9 |
|
|
faster_entersub (pTHX) |
10 |
|
|
{ |
11 |
|
|
dSP; |
12 |
|
|
dTOPss; |
13 |
|
|
|
14 |
|
|
if (SvTYPE (sv) == SVt_PVGV) |
15 |
root |
1.2 |
sv = (SV *)GvCV (sv); |
16 |
root |
1.1 |
|
17 |
|
|
if (sv) |
18 |
|
|
{ |
19 |
|
|
// only once for now |
20 |
|
|
PL_op->op_ppaddr = old_entersub; |
21 |
|
|
|
22 |
|
|
// only simple cv calls for now |
23 |
root |
1.2 |
if (!PL_perldb && !PL_tainting |
24 |
|
|
&& SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv)) |
25 |
root |
1.1 |
{ |
26 |
|
|
sv = newSViv (PTR2IV (sv)); |
27 |
root |
1.2 |
|
28 |
root |
1.1 |
ENTER; |
29 |
|
|
SAVETMPS; |
30 |
|
|
PUSHMARK (SP); |
31 |
|
|
// emulate B::CV typemap entry we don't have |
32 |
|
|
XPUSHs (sv_2mortal (sv_bless (newRV_noinc (sv), gv_stashpv ("B::CV", 1)))); |
33 |
|
|
PUTBACK; |
34 |
|
|
call_pv ("Faster::entersub", G_VOID|G_DISCARD); |
35 |
|
|
SPAGAIN; |
36 |
|
|
FREETMPS; |
37 |
|
|
LEAVE; |
38 |
|
|
} |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
return old_entersub (aTHX); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
MODULE = Faster PACKAGE = Faster |
45 |
|
|
|
46 |
root |
1.2 |
PROTOTYPES: ENABLE |
47 |
|
|
|
48 |
|
|
IV |
49 |
|
|
ppaddr (int optype) |
50 |
|
|
CODE: |
51 |
|
|
RETVAL = optype == OP_ENTERSUB |
52 |
|
|
? old_entersub |
53 |
|
|
: PL_ppaddr [optype]; |
54 |
|
|
OUTPUT: |
55 |
|
|
RETVAL |
56 |
|
|
|
57 |
root |
1.1 |
void |
58 |
|
|
hook_entersub () |
59 |
|
|
CODE: |
60 |
|
|
old_entersub = PL_ppaddr [OP_ENTERSUB]; |
61 |
|
|
PL_ppaddr [OP_ENTERSUB] = faster_entersub; |
62 |
|
|
|
63 |
|
|
|