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.3 by root, Thu Mar 9 22:32:17 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 4
5typedef CV *B__CV;
6
5static OP *(*old_entersub)(pTHX); 7static OP *(*old_entersub)(pTHX);
8
9int count = 1;
6 10
7// this is, of course, a slower entersub 11// this is, of course, a slower entersub
8static OP * 12static OP *
9faster_entersub (pTHX) 13faster_entersub (pTHX)
10{ 14{
19 // only once for now 23 // only once for now
20 PL_op->op_ppaddr = old_entersub; 24 PL_op->op_ppaddr = old_entersub;
21 25
22 // only simple cv calls for now 26 // only simple cv calls for now
23 if (!PL_perldb && !PL_tainting 27 if (!PL_perldb && !PL_tainting
24 && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv)) 28 && SvTYPE (sv) == SVt_PVCV && !CvXSUB (sv)
29 && CvSTART (sv)->op_type != OP_NULL) // shield against compiling an already-compiled op
25 { 30 {
26 sv = newSViv (PTR2IV (sv)); 31 SV *bsv = newSViv (PTR2IV (sv));
27 32
28 ENTER; 33 ENTER;
29 SAVETMPS; 34 SAVETMPS;
30 PUSHMARK (SP); 35 PUSHMARK (SP);
31 // emulate B::CV typemap entry we don't have 36 // emulate B::CV typemap entry we don't have
32 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (sv), gv_stashpv ("B::CV", 1)))); 37 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (bsv), gv_stashpv ("B::CV", 1))));
33 PUTBACK; 38 PUTBACK;
34 call_pv ("Faster::entersub", G_VOID|G_DISCARD); 39 call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL);
35 SPAGAIN; 40 SPAGAIN;
36 FREETMPS; 41 FREETMPS;
37 LEAVE; 42 LEAVE;
38 } 43 }
39 } 44 }
58hook_entersub () 63hook_entersub ()
59 CODE: 64 CODE:
60 old_entersub = PL_ppaddr [OP_ENTERSUB]; 65 old_entersub = PL_ppaddr [OP_ENTERSUB];
61 PL_ppaddr [OP_ENTERSUB] = faster_entersub; 66 PL_ppaddr [OP_ENTERSUB] = faster_entersub;
62 67
68void
69patch_cv (B::CV cv, void *ptr)
70 CODE:
71{
72 OP *op;
63 73
74 NewOp (0, op, 1, OP);
75
76 op->op_sibling = CvSTART (cv);
77 op->op_type = OP_NULL;
78 op->op_ppaddr = ptr;
79
80 CvSTART (cv) = op;
81}
82
83

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines