File Coverage

hax/sv_numcmp.c.inc
Criterion Covered Total %
statement 10 30 33.3
branch 9 38 23.6
condition n/a
subroutine n/a
pod n/a
total 19 68 27.9


line stmt bran cond sub pod time code
1             /* vi: set ft=c : */
2              
3             /* We'd like to call Perl_do_ncmp, except that isn't an exported API function
4             * Here's a near-copy of it */
5              
6             #define sv_numcmp(left, right) S_sv_numcmp(aTHX_ left, right)
7 49           static int S_sv_numcmp(pTHX_ SV *left, SV *right)
8             {
9             #ifndef HAVE_BOOL_SvIV_please_nomg
10             /* Before perl 5.18, SvIV_please_nomg() was void-returning */
11 49 50         SvIV_please_nomg(left);
    0          
12 49 50         SvIV_please_nomg(right);
    0          
13             #endif
14              
15 49           if(
16             #ifdef HAVE_BOOL_SvIV_please_nomg
17             SvIV_please_nomg(right) && SvIV_please_nomg(left)
18             #else
19 49 50         SvIOK(left) && SvIOK(right)
    50          
20             #endif
21             ) {
22             /* Compare as integers */
23 98 50         switch((SvUOK(left) ? 1 : 0) | (SvUOK(right) ? 2 : 0)) {
24 49           case 0: /* IV == IV */
25             {
26 49           const IV liv = SvIVX(left), riv = SvIVX(right);
27 49 100         if (liv < riv) return -1;
28 28 100         else if(liv > riv) return 1;
29             else return 0;
30             }
31              
32 0           case 1: /* UV == IV */
33             {
34 0           const IV riv = SvUVX(right);
35 0 0         if(riv < 0)
36             return 1;
37 0           const IV liv = SvIVX(left);
38 0 0         if (liv < riv) return -1;
39 0 0         else if(liv > riv) return 1;
40             else return 0;
41             }
42              
43 0           case 2: /* IV == UV */
44             {
45 0           const IV liv = SvUVX(left);
46 0 0         if(liv < 0)
47             return -1;
48 0           const IV riv = SvIVX(right);
49 0 0         if (liv < riv) return -1;
50 0 0         else if(liv > riv) return 1;
51             else return 0;
52             }
53              
54 0           case 3: /* UV == UV */
55             {
56 0           const UV luv = SvUVX(left), ruv = SvUVX(right);
57 0 0         if (luv < ruv) return -1;
58 0 0         else if(luv > ruv) return 1;
59             else return 0;
60             }
61             }
62             }
63             else {
64             /* Compare NVs */
65 0           NV const rnv = SvNV_nomg(right);
66 0           NV const lnv = SvNV_nomg(left);
67              
68 0 0         if (lnv < rnv) return -1;
69 0 0         else if(lnv > rnv) return 1;
70             else return 0;
71             }
72             }