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

Comparing Faster/Faster.xs (file contents):
Revision 1.1 by root, Thu Mar 9 04:41:21 2006 UTC vs.
Revision 1.7 by root, Fri Mar 10 22:18:39 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);
6
7static void
8traverse (OP *op)
9{
10}
11
12static void
13analyze (CV *cv)
14{
15 OP *op = CvSTART (cv);
16
17 traverse (op);
18}
19 8
20// this is, of course, a slower entersub 9// this is, of course, a slower entersub
21static OP * 10static OP *
22faster_entersub (pTHX) 11faster_entersub (pTHX)
23{ 12{
24 dSP; 13 dSP;
25 dTOPss; 14 dTOPss;
26 15
27 if (SvTYPE (sv) == SVt_PVGV) 16 if (SvTYPE (sv) == SVt_PVGV)
28 sv = GvCV (sv); 17 sv = (SV *)GvCV (sv);
29 18
30 if (sv) 19 if (sv)
31 { 20 {
32 sv_dump (sv);
33 // only once for now 21 // only once for now
34 PL_op->op_ppaddr = old_entersub; 22 PL_op->op_ppaddr = old_entersub;
35 23
36 // only simple cv calls for now 24 // only simple cv calls for now
25 if (!PL_perldb && !PL_tainting
37 if (!PL_perldb && 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
38 { 29 {
39 sv = newSViv (PTR2IV (sv)); 30 SV *bsv = newSViv (PTR2IV (sv));
31
40 ENTER; 32 ENTER;
41 SAVETMPS; 33 SAVETMPS;
42 PUSHMARK (SP); 34 PUSHMARK (SP);
43 // emulate B::CV typemap entry we don't have 35 // emulate B::CV typemap entry we don't have
44 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))));
45 PUTBACK; 37 PUTBACK;
46 call_pv ("Faster::entersub", G_VOID|G_DISCARD); 38 call_pv ("Faster::entersub", G_VOID|G_DISCARD|G_EVAL);
47 SPAGAIN; 39 SPAGAIN;
48 FREETMPS; 40 FREETMPS;
49 LEAVE; 41 LEAVE;
50 } 42 }
51 } 43 }
53 return old_entersub (aTHX); 45 return old_entersub (aTHX);
54} 46}
55 47
56MODULE = Faster PACKAGE = Faster 48MODULE = Faster PACKAGE = Faster
57 49
50PROTOTYPES: ENABLE
51
52IV
53ppaddr (int optype)
54 CODE:
55 RETVAL = optype == OP_ENTERSUB
56 ? (IV)old_entersub
57 : (IV)PL_ppaddr [optype];
58 OUTPUT:
59 RETVAL
60
58void 61void
59hook_entersub () 62hook_entersub ()
60 CODE: 63 CODE:
61 old_entersub = PL_ppaddr [OP_ENTERSUB]; 64 old_entersub = PL_ppaddr [OP_ENTERSUB];
62 PL_ppaddr [OP_ENTERSUB] = faster_entersub; 65 PL_ppaddr [OP_ENTERSUB] = faster_entersub;
63 66
67void
68patch_cv (B::CV cv, void *ptr)
69 CODE:
70{
71 OP *op;
64 72
73 if (!ptr)
74 croak ("NULL not allowed as code address for patch_cv");
75
76 NewOp (0, op, 1, OP);
77
78 op->op_sibling = CvSTART (cv);
79 op->op_type = OP_NULL;
80 op->op_ppaddr = ptr;
81
82 CvSTART (cv) = op;
83}
84
85

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines