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

Comparing Faster/Faster.xs (file contents):
Revision 1.2 by root, Thu Mar 9 06:03:12 2006 UTC vs.
Revision 1.6 by root, Fri Mar 10 00:11:44 2006 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4
5typedef CV *B__CV;
4 6
5static OP *(*old_entersub)(pTHX); 7static OP *(*old_entersub)(pTHX);
6 8
7// this is, of course, a slower entersub 9// this is, of course, a slower entersub
8static OP * 10static OP *
19 // only once for now 21 // only once for now
20 PL_op->op_ppaddr = old_entersub; 22 PL_op->op_ppaddr = old_entersub;
21 23
22 // only simple cv calls for now 24 // only simple cv calls for now
23 if (!PL_perldb && !PL_tainting 25 if (!PL_perldb && !PL_tainting
24 && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv)) 26 && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv)
27 && CvSTART (sv) // must exist
28 && CvSTART (sv)->op_type != OP_NULL) // shield against compiling an already-compiled op
25 { 29 {
26 sv = newSViv (PTR2IV (sv)); 30 SV *bsv = newSViv (PTR2IV (sv));
27 31
28 ENTER; 32 ENTER;
29 SAVETMPS; 33 SAVETMPS;
30 PUSHMARK (SP); 34 PUSHMARK (SP);
31 // emulate B::CV typemap entry we don't have 35 // emulate B::CV typemap entry we don't have
32 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (sv), gv_stashpv ("B::CV", 1)))); 36 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (bsv), gv_stashpv ("B::CV", 1))));
33 PUTBACK; 37 PUTBACK;
34 call_pv ("Faster::entersub", G_VOID|G_DISCARD); 38 call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL);
35 SPAGAIN; 39 SPAGAIN;
36 FREETMPS; 40 FREETMPS;
37 LEAVE; 41 LEAVE;
38 } 42 }
39 } 43 }
47 51
48IV 52IV
49ppaddr (int optype) 53ppaddr (int optype)
50 CODE: 54 CODE:
51 RETVAL = optype == OP_ENTERSUB 55 RETVAL = optype == OP_ENTERSUB
52 ? old_entersub 56 ? (IV)old_entersub
53 : PL_ppaddr [optype]; 57 : (IV)PL_ppaddr [optype];
54 OUTPUT: 58 OUTPUT:
55 RETVAL 59 RETVAL
56 60
57void 61void
58hook_entersub () 62hook_entersub ()
59 CODE: 63 CODE:
60 old_entersub = PL_ppaddr [OP_ENTERSUB]; 64 old_entersub = PL_ppaddr [OP_ENTERSUB];
61 PL_ppaddr [OP_ENTERSUB] = faster_entersub; 65 PL_ppaddr [OP_ENTERSUB] = faster_entersub;
62 66
67void
68patch_cv (B::CV cv, void *ptr)
69 CODE:
70{
71 OP *op;
63 72
73 NewOp (0, op, 1, OP);
74
75 op->op_sibling = CvSTART (cv);
76 op->op_type = OP_NULL;
77 op->op_ppaddr = ptr;
78
79 CvSTART (cv) = op;
80}
81
82

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines