Array.xs

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 57 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
↑ Summary blib/lib/Packed/Array.pm »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 MODULE = Packed::Array PACKAGE = Packed::Array
6  
7 SV *
8 FETCH(this, index)
9 SV *this
10 SV *index
11 PPCODE:
12 {
13  
14 0 IV index_offset = SvIV(index);
15 0 SV *storage = SvRV(this);
16 0 IV curlen = SvCUR(storage);
17 IV byte_size;
18 IV *data;
19 IV number;
20  
21 /* Are we big enough? */
22 0 byte_size = (index_offset + 1) * sizeof(IV);
23 0 ▶ if (byte_size > curlen) {
Branch: 1 branch
BranchTrueFalseTotal
if (byte_size > curlen) { 0 0 0
24 0 ▶ XPUSHs(sv_2mortal(newSViv(0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(0))); 0 0 0
25 } else {
26 /* Now snag the pointer to storage out of the SV */
27 0 data = (IV *)SvPVX(storage);
28 0 number = data[index_offset];
29 0 ▶ XPUSHs(sv_2mortal(newSViv(data[index_offset])));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(data[index_offset]))); 0 0 0
30 }
31 }
32  
33 SV *
34 STORE(this, index, value)
35 SV *this
36 SV *index
37 SV *value
38 PPCODE:
39 {
40 0 IV index_offset = SvIV(index);
41 0 IV value_value = SvIV(value);
42 0 SV *storage = SvRV(this);
43 0 IV curlen = SvCUR(storage);
44 IV byte_size;
45 IV *data;
46  
47 /* Are we big enough? */
48 0 byte_size = (index_offset + 1) * sizeof(IV);
49 0 ▶ if (byte_size > curlen) {
Branch: 1 branch
BranchTrueFalseTotal
if (byte_size > curlen) { 0 0 0
50 /* Apparently not. Go extend the buffer */
51 0 char *temp = malloc(byte_size - curlen);
52 0 Zero(temp, byte_size - curlen, char);
53 0 sv_catpvn(storage, temp, byte_size - curlen);
54 0 free(temp);
55 }
56  
57 /* Now snag the pointer to storage out of the SV */
58 0 data = (IV *)SvPVX(storage);
59 0 data[index_offset] = value_value;
60 0 ▶ XPUSHs(value);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(value); 0 0 0
61 }
62  
63 SV *
64 TIEARRAY(classname, ...)
65 SV *classname
66 PPCODE:
67 {
68 SV *rv;
69 SV *tiething;
70 0 HV *stash = gv_stashsv(classname, 0);
71 0 tiething = newSVpvn("", 0); /* Begin with a zero-length string */
72 0 rv = newRV_noinc(tiething);
73 0 sv_bless(rv, stash);
74 0 ▶ XPUSHs(rv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(rv); 0 0 0
75 }
76  
77 SV *
78 FETCHSIZE(this)
79 SV *this
80 PPCODE:
81 {
82 0 SV *thing = SvRV(this);
83 0 ▶ XPUSHs(sv_2mortal(newSViv(SvCUR(thing) / sizeof(IV))));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(SvCUR(thing) / sizeof(IV)))); 0 0 0
84 }
85  
86 SV *
87 STORESIZE(this, size)
88 SV *this
89 SV *size
90 PPCODE:
91 {
92 0 SV *thing = SvRV(this);
93 0 IV curlen = SvIV(thing);
94 0 IV newsize = SvIV(size) * sizeof(IV);
95 IV byte_size;
96  
97 /* Are we big enough? */
98 0 ▶ if (newsize > curlen) {
Branch: 1 branch
BranchTrueFalseTotal
if (newsize > curlen) { 0 0 0
99 /* Apparently not. Go extend the buffer */
100 0 char *temp = malloc(newsize - curlen);
101 0 Zero(temp, newsize - curlen, char);
102 0 sv_catpvn(thing, temp, newsize - curlen);
103 0 free(temp);
104 } else {
105 0 SvCUR(thing) = newsize;
106 }
107  
108 0 ▶ XPUSHs(sv_2mortal(newSViv(SvCUR(thing) / sizeof(IV))));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(SvCUR(thing) / sizeof(IV)))); 0 0 0
109 }
↑ Summary blib/lib/Packed/Array.pm »