… | |
… | |
4 | |
4 | |
5 | typedef CV *B__CV; |
5 | typedef CV *B__CV; |
6 | |
6 | |
7 | static OP *(*old_entersub)(pTHX); |
7 | static OP *(*old_entersub)(pTHX); |
8 | |
8 | |
9 | int count = 1; |
|
|
10 | |
|
|
11 | // this is, of course, a slower entersub |
9 | // this is, of course, a slower entersub |
12 | static OP * |
10 | static OP * |
13 | faster_entersub (pTHX) |
11 | faster_entersub (pTHX) |
14 | { |
12 | { |
|
|
13 | if (!PL_compcv) // only when not compiling, reduces recompiling due to op-address-shift |
|
|
14 | { |
15 | dSP; |
15 | dSP; |
16 | dTOPss; |
16 | dTOPss; |
17 | |
17 | |
18 | if (SvTYPE (sv) == SVt_PVGV) |
18 | if (SvTYPE (sv) == SVt_PVGV) |
19 | sv = (SV *)GvCV (sv); |
19 | sv = (SV *)GvCV (sv); |
20 | |
20 | |
21 | if (sv) |
21 | if (sv) |
22 | { |
22 | { |
23 | // only once for now |
23 | // only once for now |
24 | PL_op->op_ppaddr = old_entersub; |
24 | PL_op->op_ppaddr = old_entersub; |
25 | |
25 | |
26 | // only simple cv calls for now |
26 | // only simple cv calls for now |
27 | if (!PL_perldb && !PL_tainting |
27 | if (!PL_perldb && !PL_tainting |
28 | && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv) |
28 | && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv) |
|
|
29 | && CvSTART (sv) // must exist |
29 | && CvSTART (sv)->op_type != OP_NULL) // shield against compiling an already-compiled op |
30 | && CvSTART (sv)->op_type != OP_NULL) // shield against compiling an already-compiled op |
30 | { |
31 | { |
31 | SV *bsv = newSViv (PTR2IV (sv)); |
32 | SV *bsv = newSViv (PTR2IV (sv)); |
32 | |
33 | |
33 | ENTER; |
34 | ENTER; |
34 | SAVETMPS; |
35 | SAVETMPS; |
35 | PUSHMARK (SP); |
36 | PUSHMARK (SP); |
36 | // emulate B::CV typemap entry we don't have |
37 | // emulate B::CV typemap entry we don't have |
37 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (bsv), gv_stashpv ("B::CV", 1)))); |
38 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (bsv), gv_stashpv ("B::CV", 1)))); |
38 | PUTBACK; |
39 | PUTBACK; |
39 | call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL); |
40 | call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL); |
40 | SPAGAIN; |
41 | SPAGAIN; |
41 | FREETMPS; |
42 | FREETMPS; |
42 | LEAVE; |
43 | LEAVE; |
|
|
44 | } |
43 | } |
45 | } |
44 | } |
46 | } |
45 | |
47 | |
46 | return old_entersub (aTHX); |
48 | return old_entersub (aTHX); |
47 | } |
49 | } |
… | |
… | |
52 | |
54 | |
53 | IV |
55 | IV |
54 | ppaddr (int optype) |
56 | ppaddr (int optype) |
55 | CODE: |
57 | CODE: |
56 | RETVAL = optype == OP_ENTERSUB |
58 | RETVAL = optype == OP_ENTERSUB |
57 | ? old_entersub |
59 | ? (IV)old_entersub |
58 | : PL_ppaddr [optype]; |
60 | : (IV)PL_ppaddr [optype]; |
59 | OUTPUT: |
61 | OUTPUT: |
60 | RETVAL |
62 | RETVAL |
61 | |
63 | |
62 | void |
64 | void |
63 | hook_entersub () |
65 | hook_entersub () |
… | |
… | |
69 | patch_cv (B::CV cv, void *ptr) |
71 | patch_cv (B::CV cv, void *ptr) |
70 | CODE: |
72 | CODE: |
71 | { |
73 | { |
72 | OP *op; |
74 | OP *op; |
73 | |
75 | |
|
|
76 | if (!ptr) |
|
|
77 | croak ("NULL not allowed as code address for patch_cv"); |
|
|
78 | |
74 | NewOp (0, op, 1, OP); |
79 | NewOp (0, op, 1, OP); |
75 | |
80 | |
76 | op->op_sibling = CvSTART (cv); |
81 | op->op_sibling = CvSTART (cv); |
77 | op->op_type = OP_NULL; |
82 | op->op_type = OP_NULL; |
78 | op->op_ppaddr = ptr; |
83 | op->op_ppaddr = ptr; |