ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Faster/Faster.xs
Revision: 1.3
Committed: Thu Mar 9 22:32:17 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
Changes since 1.2: +24 -4 lines
Log Message:
*** empty log message ***

File Contents

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