ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Faster/Faster.xs
(Generate patch)

Comparing Faster/Faster.xs (file contents):
Revision 1.3 by root, Thu Mar 9 22:32:17 2006 UTC vs.
Revision 1.8 by root, Sun Mar 12 17:03:39 2006 UTC

4 4
5typedef CV *B__CV; 5typedef CV *B__CV;
6 6
7static OP *(*old_entersub)(pTHX); 7static OP *(*old_entersub)(pTHX);
8 8
9int count = 1;
10
11// this is, of course, a slower entersub 9// this is, of course, a slower entersub
12static OP * 10static OP *
13faster_entersub (pTHX) 11faster_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
53IV 55IV
54ppaddr (int optype) 56ppaddr (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
62void 64void
63hook_entersub () 65hook_entersub ()
69patch_cv (B::CV cv, void *ptr) 71patch_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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines