src/xs/compare.cc

filter: Statementstmt 96.8% 61 / 63 Branchbran 87.2% 75 / 86 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 91.2% 136 / 149 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/xs/clone.cc ↑ Summary blib/arch/Data/Recursive.pm »
1 #include "compare.h"
2 #include <stdint.h>
3  
4 namespace xs {
5  
6 static inline bool _elem_cmp (pTHX_ SV* f, SV* s);
7  
8 19 static inline bool hv_compare (pTHX_ HV* f, HV* s) {
9 19 ▶ if (HvUSEDKEYS(f) != HvUSEDKEYS(s)) return false;
Branch: 3 branches
BranchTrueFalseTotal
if (HvUSEDKEYS(f) != HvUSEDKEYS(s)) return false; 0 19 19
if (HvUSEDKEYS(f) != HvUSEDKEYS(s)) return false; 0 19 19
if (HvUSEDKEYS(f) != HvUSEDKEYS(s)) return false; 1 18 19
10  
11 18 HE** farr = HvARRAY(f);
12 18 ▶ if (!farr) return true; // both are empty
Branch: 1 branch
BranchTrueFalseTotal
if (!farr) return true; // both are empty 1 17 18
13 17 STRLEN fmax = HvMAX(f);
14 17 bool res = true;
15  
16 141 ▶ for (STRLEN i = 0; res && i <= fmax; ++i) {
Branch: 2 branches
BranchTrueFalseTotal
for (STRLEN i = 0; res && i <= fmax; ++i) { 136 5 141
for (STRLEN i = 0; res && i <= fmax; ++i) { 125 11 136
17 const HE* entry;
18 156 ▶ for (entry = farr[i]; res && entry; entry = HeNEXT(entry)) {
Branch: 2 branches
BranchTrueFalseTotal
for (entry = farr[i]; res && entry; entry = HeNEXT(entry)) { 151 5 156
for (entry = farr[i]; res && entry; entry = HeNEXT(entry)) { 32 119 151
19 32 const HEK* hek = HeKEY_hek(entry);
20 32 SV** sref = hv_fetchhek(s, hek, 0);
21 32 ▶ if (!sref) return false;
Branch: 1 branch
BranchTrueFalseTotal
if (!sref) return false; 1 31 32
22 31 res = _elem_cmp(aTHX_ HeVAL(entry), *sref);
23 }
24 }
25  
26 16 return res;
27 }
28  
29 10 static inline bool av_compare (pTHX_ AV* f, AV* s) {
30 10 SSize_t lasti = AvFILLp(f);
31 10 ▶ if (lasti != AvFILLp(s)) return false;
Branch: 1 branch
BranchTrueFalseTotal
if (lasti != AvFILLp(s)) return false; 0 10 10
32 10 SV** fl = AvARRAY(f);
33 10 SV** sl = AvARRAY(s);
34  
35 10 bool res = true;
36 529 ▶ while (res && lasti-- >= 0) {
Branch: 3 branches
BranchTrueFalseTotal
while (res && lasti-- >= 0) { 527 2 529
while (res && lasti-- >= 0) { 520 7 527
while (res && lasti-- >= 0) { 520 9 529
37 520 ▶ if ((bool)*fl ^ (bool)*sl) return false; // one is null while another is not.
Branch: 1 branch
BranchTrueFalseTotal
if ((bool)*fl ^ (bool)*sl) return false; // one is null while another is not. 1 519 520
38 519 res = _elem_cmp(aTHX_ *fl++, *sl++);
39 }
40 9 return res;
41 }
42  
43 607 static inline bool _elem_cmp (pTHX_ SV* f, SV* s) {
44 607 ▶ if (f == s) return true;
Branch: 1 branch
BranchTrueFalseTotal
if (f == s) return true; 493 114 607
45  
46 114 ▶ if (SvROK(f) | SvROK(s)) { /* unroll references */
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(f) | SvROK(s)) { /* unroll references */ 54 60 114
47 125 ▶ while (SvROK(f) & SvROK(s)) {
Branch: 1 branch
BranchTrueFalseTotal
while (SvROK(f) & SvROK(s)) { 79 46 125
48 79 SV* fval = SvRV(f);
49 79 SV* sval = SvRV(s);
50 79 ▶ if (SvOBJECT(fval) ^ SvOBJECT(sval)) return false;
Branch: 1 branch
BranchTrueFalseTotal
if (SvOBJECT(fval) ^ SvOBJECT(sval)) return false; 2 77 79
51 77 ▶ if (SvOBJECT(fval)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOBJECT(fval)) { 12 65 77
52 12 ▶ if (fval == sval) return true;
Branch: 1 branch
BranchTrueFalseTotal
if (fval == sval) return true; 1 11 12
53 11 ▶ if (SvSTASH(fval) != SvSTASH(sval)) return false;
Branch: 1 branch
BranchTrueFalseTotal
if (SvSTASH(fval) != SvSTASH(sval)) return false; 2 9 11
54 9 ▶ if (HvAMAGIC(SvSTASH(fval))) { // class has operator overloadings
Branch: 1 branch
BranchTrueFalseTotal
if (HvAMAGIC(SvSTASH(fval))) { // class has operator overloadings 4 5 9
55 4 SV* const tmpsv = amagic_call(f, s, eq_amg, 0);
56 4 ▶ if (tmpsv) return SvTRUE(tmpsv); // class has '==' operator overloading
Branch: 1 branch
BranchTrueFalseTotal
if (tmpsv) return SvTRUE(tmpsv); // class has '==' operator overloading 3 1 4
57 // otherwise compare object's data structure as it wasn't blessed at all.
58 }
59 }
60 71 f = fval;
61 71 s = sval;
62 }
63 46 ▶ if (SvROK(f) | SvROK(s)) return false; /* asymmetric references */
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(f) | SvROK(s)) return false; /* asymmetric references */ 4 42 46
64 42 ▶ if (f == s) return true;
Branch: 1 branch
BranchTrueFalseTotal
if (f == s) return true; 2 40 42
65 }
66  
67 100 switch (SvTYPE(f)) {
68 65 case SVt_IV:
69 case SVt_NV:
70 case SVt_PV:
71 case SVt_PVIV:
72 case SVt_PVNV:
73 case SVt_NULL:
74 case SVt_PVMG:
75 65 ▶ if (SvOK(f) && SvOK(s)) { // both are not undefs
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(f) && SvOK(s)) { // both are not undefs 62 3 65
if (SvOK(f) && SvOK(s)) { // both are not undefs 59 3 62
76 59 ▶ if (SvTYPE(s) > SVt_PVMG) return false; // wrong type
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(s) > SVt_PVMG) return false; // wrong type 0 59 59
77 83 ▶ if (SvPOK(f) | SvPOK(s)) return strEQ(SvPV_nolen(f), SvPV_nolen(s)); // both strings
Branch: 2 branches
BranchTrueFalseTotal
if (SvPOK(f) | SvPOK(s)) return strEQ(SvPV_nolen(f), SvPV_nolen(s)); // both strings 12 47 59
if (SvPOK(f) | SvPOK(s)) return strEQ(SvPV_nolen(f), SvPV_nolen(s)); // both strings 6 6 12
78 47 ▶ if (SvNOK(f) | SvNOK(s)) return SvNV(f) == SvNV(s); // natural values
Branch: 1 branch
BranchTrueFalseTotal
if (SvNOK(f) | SvNOK(s)) return SvNV(f) == SvNV(s); // natural values 4 43 47
79 43 return SvIVX(f) == SvIVX(s); // compare as integers
80 }
81 6 ▶ return !(SvOK(f) || SvOK(s));
Branch: 2 branches
BranchTrueFalseTotal
return !(SvOK(f) || SvOK(s)); 3 3 6
return !(SvOK(f) || SvOK(s)); 1 2 3
82 19 case SVt_PVHV:
83 19 ▶ return SvTYPE(s) == SVt_PVHV && hv_compare(aTHX_ (HV*)f, (HV*)s);
Branch: 2 branches
BranchTrueFalseTotal
return SvTYPE(s) == SVt_PVHV && hv_compare(aTHX_ (HV*)f, (HV*)s); 19 0 19
return SvTYPE(s) == SVt_PVHV && hv_compare(aTHX_ (HV*)f, (HV*)s); 12 7 19
84 10 case SVt_PVAV:
85 10 ▶ return SvTYPE(s) == SVt_PVAV && av_compare(aTHX_ (AV*)f, (AV*)s);
Branch: 2 branches
BranchTrueFalseTotal
return SvTYPE(s) == SVt_PVAV && av_compare(aTHX_ (AV*)f, (AV*)s); 10 0 10
return SvTYPE(s) == SVt_PVAV && av_compare(aTHX_ (AV*)f, (AV*)s); 7 3 10
86 1 case SVt_PVIO:
87 1 ▶ return SvTYPE(s) == SVt_PVIO && PerlIO_fileno(IoIFP(f)) == PerlIO_fileno(IoIFP(s));
Branch: 2 branches
BranchTrueFalseTotal
return SvTYPE(s) == SVt_PVIO && PerlIO_fileno(IoIFP(f)) == PerlIO_fileno(IoIFP(s)); 1 0 1
return SvTYPE(s) == SVt_PVIO && PerlIO_fileno(IoIFP(f)) == PerlIO_fileno(IoIFP(s)); 0 1 1
88 3 case SVt_REGEXP:
89 9 ▶ return SvTYPE(s) == SVt_REGEXP && strEQ(SvPV_nolen(f), SvPV_nolen(s));
Branch: 3 branches
BranchTrueFalseTotal
return SvTYPE(s) == SVt_REGEXP && strEQ(SvPV_nolen(f), SvPV_nolen(s)); 3 0 3
return SvTYPE(s) == SVt_REGEXP && strEQ(SvPV_nolen(f), SvPV_nolen(s)); 3 0 3
return SvTYPE(s) == SVt_REGEXP && strEQ(SvPV_nolen(f), SvPV_nolen(s)); 1 2 3
90 2 case SVt_PVCV:
91 case SVt_PVGV:
92 2 return false; /* already checked by pointers equality */
93 0 default:
94 0 return false;
95 }
96 }
97  
98 57 bool compare (const Sv& f, const Sv& s) {
99 57 ▶ if ((bool)f ^ (bool)s) return false;
Branch: 1 branch
BranchTrueFalseTotal
if ((bool)f ^ (bool)s) return false; 0 57 57
100 57 return _elem_cmp(aTHX_ f, s); // _elem_cmp cannot receive NULLs except for when both are NULLs
101 }
102  
103  
104 }
« src/xs/clone.cc ↑ Summary blib/arch/Data/Recursive.pm »