| 1 |
|
| #define PERL_NO_GET_CONTEXT |
| 2 |
|
| #include "EXTERN.h" |
| 3 |
|
| #include "perl.h" |
| 4 |
|
| #include "XSUB.h" |
| 5 |
|
| #include "ppport.h" |
| 6 |
|
| #include "sortedset.h" |
| 7 |
|
| |
| 8 |
|
| #define EXTRACT(sv) \ |
| 9 |
|
| if (!sv_isobject(sv) || !sv_derived_from(sv, "Data::SortedSet::Shared")) \ |
| 10 |
|
| croak("Expected a Data::SortedSet::Shared object"); \ |
| 11 |
|
| SsHandle *h = INT2PTR(SsHandle*, SvIV(SvRV(sv))); \ |
| 12 |
|
| if (!h) croak("Attempted to use a destroyed Data::SortedSet::Shared object"); \ |
| 13 |
|
| SsHandle *h0 = h; PERL_UNUSED_VAR(h0); \ |
| 14 |
|
| sv_2mortal(SvREFCNT_inc(SvRV(sv))) |
| 15 |
|
| |
| 16 |
|
| /* Re-read the handle after a call that can run Perl code (tied/overloaded |
| 17 |
|
| * argument magic, tied-array fetches). That code may call $obj->DESTROY |
| 18 |
|
| * explicitly, which frees the handle and zeroes the IV; EXTRACT's mortal |
| 19 |
|
| * pins the referent only against refcount-driven destruction, not an |
| 20 |
|
| * explicit DESTROY, so the local `h` would dangle. Used only where magic |
| 21 |
|
| * can actually intervene between EXTRACT and the first use of h. */ |
| 22 |
|
| /* The same Perl that can destroy the handle can also REPLACE the invocant |
| 23 |
|
| * ($obj = 42 or undef $obj from an overload handler mutates ST(0), because Perl |
| 24 |
|
| * passes aliases), so SvROK must be re-checked before SvRV -- otherwise SvRV |
| 25 |
|
| * would run on a non-reference. */ |
| 26 |
|
| #define REEXTRACT(sv) \ |
| 27 |
|
| if (!SvROK(sv)) \ |
| 28 |
|
| croak("Data::SortedSet::Shared object was replaced during the call"); \ |
| 29 |
|
| h = INT2PTR(SsHandle*, SvIV(SvRV(sv))); \ |
| 30 |
|
| if (h != h0) croak("Data::SortedSet::Shared object replaced or destroyed during the call") |
| 31 |
|
| |
| 32 |
|
| #define MAKE_OBJ(class, handle) \ |
| 33 |
|
| SV *obj = newSViv(PTR2IV(handle)); \ |
| 34 |
|
| SV *ref = newRV_noinc(obj); \ |
| 35 |
|
| sv_bless(ref, gv_stashpv(class, GV_ADD)); \ |
| 36 |
|
| RETVAL = ref |
| 37 |
|
| |
| 38 |
|
| /* collect ranks [S0, S0+LEN) (REV = reverse order) and push onto the stack: |
| 39 |
|
| members, or (member,score) pairs if WS. The read lock must be HELD on entry; |
| 40 |
|
| it is released (after the snapshot) before anything is pushed. */ |
| 41 |
|
| #define EMIT_COLLECTED(S0, LEN, REV, WS) STMT_START { \ |
| 42 |
|
| ss_rcollect_t col = { NULL, NULL, 0, 0 }; \ |
| 43 |
|
| int ok_ = ss_collect_range(h, (S0), (LEN), (REV), &col); \ |
| 44 |
|
| if (!h->readonly) ss_rwlock_rdunlock(h); /* frozen view took no read lock */ \ |
| 45 |
|
| if (!ok_) { free(col.members); free(col.scores); croak("range: out of memory"); } \ |
| 46 |
|
| EXTEND(SP, (SSize_t)((WS) ? col.n * 2 : col.n)); \ |
| 47 |
|
| for (size_t i_ = 0; i_ < col.n; i_++) { \ |
| 48 |
|
| PUSHs(sv_2mortal(newSViv((IV)col.members[i_]))); \ |
| 49 |
|
| if (WS) PUSHs(sv_2mortal(newSVnv(col.scores[i_]))); \ |
| 50 |
|
| } \ |
| 51 |
|
| free(col.members); free(col.scores); \ |
| 52 |
|
| } STMT_END |
| 53 |
|
| |
| 54 |
|
| /* parse trailing "withscores => bool", "limit => n", "offset => n" options */ |
| 55 |
85 |
| static void ss_parse_range_opts(pTHX_ SV **sp, int first, int items, int *ws, IV *limit, IV *offset) { |
| 56 |
85 |
▶ | if ((items - first) % 2 != 0) croak("range options must be key => value pairs"); |
Branch: 1 branch
| Branch | True | False | Total |
| if ((items - first) % 2 != 0) croak("range options must be key => value pairs"); |
0 |
85 |
85 |
|
| 57 |
101 |
▶ | for (int ai = first; ai + 1 < items; ai += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (int ai = first; ai + 1 < items; ai += 2) { |
16 |
85 |
101 |
|
| 58 |
16 |
| const char *k = SvPV_nolen(sp[ai]); |
| 59 |
16 |
▶ | if (!strcmp(k, "withscores")) *ws = SvTRUE(sp[ai+1]); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!strcmp(k, "withscores")) *ws = SvTRUE(sp[ai+1]); |
6 |
10 |
16 |
|
| 60 |
10 |
▶ | else if (limit && !strcmp(k, "limit")) *limit = SvIV(sp[ai+1]); |
Branch: 2 branches
| Branch | True | False | Total |
| else if (limit && !strcmp(k, "limit")) *limit = SvIV(sp[ai+1]); |
10 |
0 |
10 |
| else if (limit && !strcmp(k, "limit")) *limit = SvIV(sp[ai+1]); |
5 |
5 |
10 |
|
| 61 |
5 |
▶ | else if (offset && !strcmp(k, "offset")) *offset = SvIV(sp[ai+1]); |
Branch: 2 branches
| Branch | True | False | Total |
| else if (offset && !strcmp(k, "offset")) *offset = SvIV(sp[ai+1]); |
5 |
0 |
5 |
| else if (offset && !strcmp(k, "offset")) *offset = SvIV(sp[ai+1]); |
5 |
0 |
5 |
|
| 62 |
0 |
| else croak("unknown option '%s'", k); |
| 63 |
|
| } |
| 64 |
85 |
| } |
| 65 |
|
| |
| 66 |
|
| /* normalize Perl-style [start, stop] rank indices into a forward [*a, *b] window |
| 67 |
|
| (negatives count from the end); returns true if the window is non-empty */ |
| 68 |
18 |
| static int ss_rank_window(uint32_t cnt, IV start, IV stop, IV *a, IV *b) { |
| 69 |
18 |
| *a = start; *b = stop; |
| 70 |
18 |
▶ | if (*a < 0) *a += (IV)cnt; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*a < 0) *a += (IV)cnt; |
1 |
17 |
18 |
|
| 71 |
18 |
▶ | if (*b < 0) *b += (IV)cnt; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*b < 0) *b += (IV)cnt; |
10 |
8 |
18 |
|
| 72 |
18 |
▶ | if (*a < 0) *a = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*a < 0) *a = 0; |
0 |
18 |
18 |
|
| 73 |
18 |
▶ | if (*b >= (IV)cnt) *b = (IV)cnt - 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*b >= (IV)cnt) *b = (IV)cnt - 1; |
1 |
17 |
18 |
|
| 74 |
18 |
▶ | return cnt > 0 && *a <= *b; |
Branch: 2 branches
| Branch | True | False | Total |
| return cnt > 0 && *a <= *b; |
17 |
1 |
18 |
| return cnt > 0 && *a <= *b; |
16 |
1 |
17 |
|
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
4 |
| static void ss_free_snapshot(pTHX_ void *ptr) { |
| 78 |
4 |
| ss_rcollect_t *col = (ss_rcollect_t *)ptr; |
| 79 |
4 |
| free(col->members); free(col->scores); |
| 80 |
4 |
| Safefree(col); |
| 81 |
4 |
| } |
| 82 |
|
| |
| 83 |
|
| MODULE = Data::SortedSet::Shared PACKAGE = Data::SortedSet::Shared |
| 84 |
|
| |
| 85 |
|
| PROTOTYPES: DISABLE |
| 86 |
|
| |
| 87 |
|
| SV * |
| 88 |
|
| new(class, path, max_entries, ...) |
| 89 |
|
| const char *class |
| 90 |
|
| SV *path |
| 91 |
|
| UV max_entries |
| 92 |
|
| PREINIT: |
| 93 |
|
| char errbuf[SS_ERR_BUFLEN]; |
| 94 |
|
| CODE: |
| 95 |
49 |
▶ | if (max_entries > UINT32_MAX) croak("Data::SortedSet::Shared->new: max_entries exceeds 2^32"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (max_entries > UINT32_MAX) croak("Data::SortedSet::Shared->new: max_entries exceeds 2^32"); |
0 |
49 |
49 |
|
| 96 |
|
| /* resolve the trailing optional mode BEFORE capturing the path PV: its |
| 97 |
|
| get-magic runs arbitrary Perl that can realloc/free path's PV */ |
| 98 |
49 |
▶ | mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; |
Branch: 4 branches
| Branch | True | False | Total |
| mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; |
12 |
37 |
49 |
| mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; |
10 |
2 |
12 |
| mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; |
0 |
10 |
10 |
| mode_t mode = (items > 3 && (SvGETMAGIC(ST(3)), SvOK(ST(3)))) ? (mode_t)SvUV(ST(3)) : 0600; |
2 |
10 |
12 |
|
| 99 |
72 |
▶ | const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
8 |
41 |
49 |
| const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
0 |
8 |
8 |
| const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
23 |
26 |
49 |
|
| 100 |
49 |
| SsHandle *h = ss_create(p, (uint32_t)max_entries, mode, errbuf); |
| 101 |
49 |
▶ | if (!h) croak("Data::SortedSet::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::SortedSet::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
6 |
43 |
49 |
| if (!h) croak("Data::SortedSet::Shared->new: %s", errbuf[0] ? errbuf : "out of memory"); |
6 |
0 |
6 |
|
| 102 |
43 |
| MAKE_OBJ(class, h); |
| 103 |
|
| OUTPUT: |
| 104 |
|
| RETVAL |
| 105 |
|
| |
| 106 |
|
| SV * |
| 107 |
|
| new_memfd(class, name, max_entries) |
| 108 |
|
| const char *class |
| 109 |
|
| SV *name |
| 110 |
|
| UV max_entries |
| 111 |
|
| PREINIT: |
| 112 |
|
| char errbuf[SS_ERR_BUFLEN]; |
| 113 |
|
| CODE: |
| 114 |
1 |
▶ | if (max_entries > UINT32_MAX) croak("Data::SortedSet::Shared->new_memfd: max_entries exceeds 2^32"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (max_entries > UINT32_MAX) croak("Data::SortedSet::Shared->new_memfd: max_entries exceeds 2^32"); |
0 |
1 |
1 |
|
| 115 |
|
| /* capture the name PV here, AFTER the max_entries INPUT conversion: its |
| 116 |
|
| get-magic runs arbitrary Perl that can realloc/free name's PV */ |
| 117 |
2 |
▶ | const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; |
0 |
1 |
1 |
| const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; |
0 |
0 |
0 |
| const char *nm = (SvGETMAGIC(name), SvOK(name)) ? SvPV_nolen(name) : NULL; |
1 |
0 |
1 |
|
| 118 |
1 |
| SsHandle *h = ss_create_memfd(nm, (uint32_t)max_entries, errbuf); |
| 119 |
1 |
▶ | if (!h) croak("Data::SortedSet::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::SortedSet::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
0 |
1 |
1 |
| if (!h) croak("Data::SortedSet::Shared->new_memfd: %s", errbuf[0] ? errbuf : "out of memory"); |
0 |
0 |
0 |
|
| 120 |
1 |
| MAKE_OBJ(class, h); |
| 121 |
|
| OUTPUT: |
| 122 |
|
| RETVAL |
| 123 |
|
| |
| 124 |
|
| SV * |
| 125 |
|
| new_from_fd(class, fd) |
| 126 |
|
| const char *class |
| 127 |
|
| int fd |
| 128 |
|
| PREINIT: |
| 129 |
|
| char errbuf[SS_ERR_BUFLEN]; |
| 130 |
|
| CODE: |
| 131 |
2 |
| SsHandle *h = ss_open_fd(fd, errbuf); |
| 132 |
2 |
▶ | if (!h) croak("Data::SortedSet::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h) croak("Data::SortedSet::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
1 |
2 |
| if (!h) croak("Data::SortedSet::Shared->new_from_fd: %s", errbuf[0] ? errbuf : "out of memory"); |
1 |
0 |
1 |
|
| 133 |
1 |
| MAKE_OBJ(class, h); |
| 134 |
|
| OUTPUT: |
| 135 |
|
| RETVAL |
| 136 |
|
| |
| 137 |
|
| SV * |
| 138 |
|
| new_readonly(class, path) |
| 139 |
|
| const char *class |
| 140 |
|
| SV *path |
| 141 |
|
| PREINIT: |
| 142 |
|
| char errbuf[SS_ERR_BUFLEN]; |
| 143 |
|
| CODE: |
| 144 |
|
| /* Open a FROZEN (sealed) file read-only: O_RDONLY + PROT_READ, no lock |
| 145 |
|
| ever. A sealed file is immutable and no read path writes the mapping, |
| 146 |
|
| so queries take no reader-slot / rwlock traffic and any number of |
| 147 |
|
| processes can share one PROT_READ mapping (same architecture; the |
| 148 |
|
| magic rejects a wrong-endian file). */ |
| 149 |
11 |
▶ | const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
0 |
6 |
6 |
| const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
0 |
0 |
0 |
| const char *p = (SvGETMAGIC(path), SvOK(path)) ? SvPV_nolen(path) : NULL; |
5 |
1 |
6 |
|
| 150 |
6 |
▶ | if (!p) croak("Data::SortedSet::Shared->new_readonly: path is required"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p) croak("Data::SortedSet::Shared->new_readonly: path is required"); |
1 |
5 |
6 |
|
| 151 |
5 |
| SsHandle *h = ss_open_readonly(p, errbuf); |
| 152 |
5 |
▶ | if (!h) croak("Data::SortedSet::Shared->new_readonly: %s", errbuf); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h) croak("Data::SortedSet::Shared->new_readonly: %s", errbuf); |
2 |
3 |
5 |
|
| 153 |
3 |
| class = SvPV_nolen(ST(0)); /* re-read the class PV: path's get-magic may have moved ST(0) before the bless */ |
| 154 |
3 |
| MAKE_OBJ(class, h); |
| 155 |
|
| OUTPUT: |
| 156 |
|
| RETVAL |
| 157 |
|
| |
| 158 |
|
| void |
| 159 |
|
| DESTROY(self) |
| 160 |
|
| SV *self |
| 161 |
|
| CODE: |
| 162 |
49 |
▶ | if (sv_isobject(self) && sv_derived_from(self, "Data::SortedSet::Shared")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (sv_isobject(self) && sv_derived_from(self, "Data::SortedSet::Shared")) { |
49 |
0 |
49 |
| if (sv_isobject(self) && sv_derived_from(self, "Data::SortedSet::Shared")) { |
49 |
0 |
49 |
|
| 163 |
49 |
| SsHandle *h = INT2PTR(SsHandle*, SvIV(SvRV(self))); |
| 164 |
49 |
▶ | if (h) { sv_setiv(SvRV(self), 0); ss_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (h) { sv_setiv(SvRV(self), 0); ss_destroy(h); } /* null first: activates EXTRACT's use-after-destroy croak + makes a double DESTROY a no-op */ |
48 |
1 |
49 |
|
| 165 |
|
| } |
| 166 |
|
| |
| 167 |
|
| UV |
| 168 |
|
| count(self) |
| 169 |
|
| SV *self |
| 170 |
|
| PREINIT: |
| 171 |
30 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
30 |
0 |
30 |
| EXTRACT(self); |
0 |
30 |
30 |
| EXTRACT(self); |
1 |
29 |
30 |
|
| 172 |
|
| CODE: |
| 173 |
29 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
27 |
2 |
29 |
|
| 174 |
29 |
| RETVAL = h->hdr->count; |
| 175 |
29 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
27 |
2 |
29 |
|
| 176 |
|
| OUTPUT: |
| 177 |
|
| RETVAL |
| 178 |
|
| |
| 179 |
|
| UV |
| 180 |
|
| max_entries(self) |
| 181 |
|
| SV *self |
| 182 |
|
| PREINIT: |
| 183 |
4 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
4 |
0 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
|
| 184 |
|
| CODE: |
| 185 |
4 |
▶ | RETVAL = h->hdr->max_entries; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->hdr->max_entries; |
0 |
4 |
4 |
|
| 186 |
|
| OUTPUT: |
| 187 |
|
| RETVAL |
| 188 |
|
| |
| 189 |
|
| void |
| 190 |
|
| freeze(self) |
| 191 |
|
| SV *self |
| 192 |
|
| PREINIT: |
| 193 |
3 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3 |
0 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
|
| 194 |
|
| CODE: |
| 195 |
3 |
▶ | if (h->readonly) croak("Data::SortedSet::Shared->freeze: cannot freeze a read-only handle"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::SortedSet::Shared->freeze: cannot freeze a read-only handle"); |
2 |
1 |
3 |
|
| 196 |
1 |
▶ | if (ss_freeze(h) != 0) croak("Data::SortedSet::Shared->freeze: msync: %s", strerror(errno)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (ss_freeze(h) != 0) croak("Data::SortedSet::Shared->freeze: msync: %s", strerror(errno)); |
0 |
1 |
1 |
|
| 197 |
1 |
| h->readonly = 1; /* this handle now rejects mutation too (the file is sealed) */ |
| 198 |
|
| |
| 199 |
|
| UV |
| 200 |
|
| frozen(self) |
| 201 |
|
| SV *self |
| 202 |
|
| PREINIT: |
| 203 |
3 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3 |
0 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
|
| 204 |
|
| CODE: |
| 205 |
3 |
▶ | RETVAL = h->hdr->sealed ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->hdr->sealed ? 1 : 0; |
0 |
3 |
3 |
|
| 206 |
|
| OUTPUT: |
| 207 |
|
| RETVAL |
| 208 |
|
| |
| 209 |
|
| UV |
| 210 |
|
| readonly(self) |
| 211 |
|
| SV *self |
| 212 |
|
| PREINIT: |
| 213 |
3 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
3 |
0 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
| EXTRACT(self); |
0 |
3 |
3 |
|
| 214 |
|
| CODE: |
| 215 |
3 |
▶ | RETVAL = h->readonly ? 1 : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->readonly ? 1 : 0; |
0 |
3 |
3 |
|
| 216 |
|
| OUTPUT: |
| 217 |
|
| RETVAL |
| 218 |
|
| |
| 219 |
|
| void |
| 220 |
|
| clear(self) |
| 221 |
|
| SV *self |
| 222 |
|
| PREINIT: |
| 223 |
7 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
7 |
0 |
7 |
| EXTRACT(self); |
0 |
7 |
7 |
| EXTRACT(self); |
0 |
7 |
7 |
|
| 224 |
|
| CODE: |
| 225 |
7 |
▶ | if (h->readonly) croak("Data::SortedSet::Shared->clear: sorted set is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::SortedSet::Shared->clear: sorted set is frozen (read-only)"); |
2 |
5 |
7 |
|
| 226 |
5 |
| ss_rwlock_wrlock(h); |
| 227 |
5 |
▶ | if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->clear: sorted set is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->clear: sorted set is frozen (read-only)"); } |
0 |
5 |
5 |
|
| 228 |
5 |
| ss_clear_locked(h); |
| 229 |
5 |
| ss_rwlock_wrunlock(h); |
| 230 |
|
| |
| 231 |
|
| SV * |
| 232 |
|
| add(self, member, score) |
| 233 |
|
| SV *self |
| 234 |
|
| IV member |
| 235 |
|
| NV score |
| 236 |
|
| PREINIT: |
| 237 |
95355 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
95355 |
0 |
95355 |
| EXTRACT(self); |
0 |
95355 |
95355 |
| EXTRACT(self); |
0 |
95355 |
95355 |
|
| 238 |
|
| int rc; |
| 239 |
|
| CODE: |
| 240 |
95355 |
▶ | if (h->readonly) croak("Data::SortedSet::Shared->add: sorted set is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::SortedSet::Shared->add: sorted set is frozen (read-only)"); |
2 |
95353 |
95355 |
|
| 241 |
95353 |
▶ | if (score != score) croak("add: score must not be NaN"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (score != score) croak("add: score must not be NaN"); |
1 |
95352 |
95353 |
|
| 242 |
95352 |
| ss_rwlock_wrlock(h); |
| 243 |
95352 |
▶ | if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->add: sorted set is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->add: sorted set is frozen (read-only)"); } |
0 |
95352 |
95352 |
|
| 244 |
95352 |
| rc = ss_add_locked(h, (int64_t)member, (double)score); |
| 245 |
95352 |
| __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
| 246 |
95352 |
| ss_rwlock_wrunlock(h); |
| 247 |
95352 |
▶ | RETVAL = (rc < 0) ? &PL_sv_undef : newSViv(rc); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (rc < 0) ? &PL_sv_undef : newSViv(rc); |
95350 |
2 |
95352 |
|
| 248 |
|
| OUTPUT: |
| 249 |
|
| RETVAL |
| 250 |
|
| |
| 251 |
|
| SV * |
| 252 |
|
| score(self, member) |
| 253 |
|
| SV *self |
| 254 |
|
| IV member |
| 255 |
|
| PREINIT: |
| 256 |
65727 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
65727 |
0 |
65727 |
| EXTRACT(self); |
0 |
65727 |
65727 |
| EXTRACT(self); |
0 |
65727 |
65727 |
|
| 257 |
|
| double sc; |
| 258 |
|
| CODE: |
| 259 |
65727 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
65722 |
5 |
65727 |
|
| 260 |
65727 |
| int found = ss_idx_get(h, (int64_t)member, &sc); |
| 261 |
65727 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
65722 |
5 |
65727 |
|
| 262 |
65727 |
▶ | RETVAL = found ? newSVnv(sc) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = found ? newSVnv(sc) : &PL_sv_undef; |
65725 |
2 |
65727 |
|
| 263 |
|
| OUTPUT: |
| 264 |
|
| RETVAL |
| 265 |
|
| |
| 266 |
|
| bool |
| 267 |
|
| exists(self, member) |
| 268 |
|
| SV *self |
| 269 |
|
| IV member |
| 270 |
|
| PREINIT: |
| 271 |
7 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
7 |
0 |
7 |
| EXTRACT(self); |
0 |
7 |
7 |
| EXTRACT(self); |
0 |
7 |
7 |
|
| 272 |
|
| double sc; |
| 273 |
|
| CODE: |
| 274 |
7 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
5 |
2 |
7 |
|
| 275 |
7 |
| RETVAL = ss_idx_get(h, (int64_t)member, &sc); |
| 276 |
7 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
5 |
2 |
7 |
|
| 277 |
|
| OUTPUT: |
| 278 |
|
| RETVAL |
| 279 |
|
| |
| 280 |
|
| bool |
| 281 |
|
| remove(self, member) |
| 282 |
|
| SV *self |
| 283 |
|
| IV member |
| 284 |
|
| PREINIT: |
| 285 |
23438 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
23438 |
0 |
23438 |
| EXTRACT(self); |
0 |
23438 |
23438 |
| EXTRACT(self); |
0 |
23438 |
23438 |
|
| 286 |
|
| CODE: |
| 287 |
23438 |
▶ | if (h->readonly) croak("Data::SortedSet::Shared->remove: sorted set is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::SortedSet::Shared->remove: sorted set is frozen (read-only)"); |
2 |
23436 |
23438 |
|
| 288 |
23436 |
| ss_rwlock_wrlock(h); |
| 289 |
23436 |
▶ | if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->remove: sorted set is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->remove: sorted set is frozen (read-only)"); } |
0 |
23436 |
23436 |
|
| 290 |
23436 |
| RETVAL = ss_remove_locked(h, (int64_t)member); |
| 291 |
23436 |
| __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
| 292 |
23436 |
| ss_rwlock_wrunlock(h); |
| 293 |
|
| OUTPUT: |
| 294 |
|
| RETVAL |
| 295 |
|
| |
| 296 |
|
| NV |
| 297 |
|
| incr(self, member, delta) |
| 298 |
|
| SV *self |
| 299 |
|
| IV member |
| 300 |
|
| NV delta |
| 301 |
|
| PREINIT: |
| 302 |
16398 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
16398 |
0 |
16398 |
| EXTRACT(self); |
0 |
16398 |
16398 |
| EXTRACT(self); |
0 |
16398 |
16398 |
|
| 303 |
|
| double out; |
| 304 |
|
| int rc; |
| 305 |
|
| CODE: |
| 306 |
16398 |
▶ | if (h->readonly) croak("Data::SortedSet::Shared->incr: sorted set is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::SortedSet::Shared->incr: sorted set is frozen (read-only)"); |
2 |
16396 |
16398 |
|
| 307 |
16396 |
▶ | if (delta != delta) croak("incr: delta must not be NaN"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (delta != delta) croak("incr: delta must not be NaN"); |
1 |
16395 |
16396 |
|
| 308 |
16395 |
| ss_rwlock_wrlock(h); |
| 309 |
16395 |
▶ | if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->incr: sorted set is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->incr: sorted set is frozen (read-only)"); } |
0 |
16395 |
16395 |
|
| 310 |
16395 |
| rc = ss_incr_locked(h, (int64_t)member, (double)delta, &out); |
| 311 |
16395 |
| __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
| 312 |
16395 |
| ss_rwlock_wrunlock(h); |
| 313 |
16395 |
▶ | if (rc == -1) croak("incr: max_entries exhausted"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc == -1) croak("incr: max_entries exhausted"); |
0 |
16395 |
16395 |
|
| 314 |
16395 |
▶ | if (rc == -2) croak("incr: result is NaN"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc == -2) croak("incr: result is NaN"); |
1 |
16394 |
16395 |
|
| 315 |
16394 |
▶ | RETVAL = out; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = out; |
16388 |
6 |
16394 |
|
| 316 |
|
| OUTPUT: |
| 317 |
|
| RETVAL |
| 318 |
|
| |
| 319 |
|
| void |
| 320 |
|
| pop_min(self) |
| 321 |
|
| SV *self |
| 322 |
|
| PREINIT: |
| 323 |
14952 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
14952 |
0 |
14952 |
| EXTRACT(self); |
0 |
14952 |
14952 |
| EXTRACT(self); |
0 |
14952 |
14952 |
|
| 324 |
|
| PPCODE: |
| 325 |
|
| { |
| 326 |
|
| int64_t m; double s; int ok; |
| 327 |
14952 |
▶ | if (h->readonly) croak("Data::SortedSet::Shared->pop_min: sorted set is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::SortedSet::Shared->pop_min: sorted set is frozen (read-only)"); |
2 |
14950 |
14952 |
|
| 328 |
14950 |
| ss_rwlock_wrlock(h); |
| 329 |
14950 |
▶ | if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->pop_min: sorted set is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->pop_min: sorted set is frozen (read-only)"); } |
0 |
14950 |
14950 |
|
| 330 |
14950 |
| ok = ss_pop_locked(h, 0, &m, &s); |
| 331 |
14950 |
▶ | if (ok) __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
Branch: 1 branch
| Branch | True | False | Total |
| if (ok) __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
14949 |
1 |
14950 |
|
| 332 |
14950 |
| ss_rwlock_wrunlock(h); |
| 333 |
14950 |
▶ | if (ok) { EXTEND(SP, 2); PUSHs(sv_2mortal(newSViv((IV)m))); PUSHs(sv_2mortal(newSVnv(s))); } |
Branch: 2 branches
| Branch | True | False | Total |
| if (ok) { EXTEND(SP, 2); PUSHs(sv_2mortal(newSViv((IV)m))); PUSHs(sv_2mortal(newSVnv(s))); } |
14949 |
1 |
14950 |
| if (ok) { EXTEND(SP, 2); PUSHs(sv_2mortal(newSViv((IV)m))); PUSHs(sv_2mortal(newSVnv(s))); } |
0 |
14949 |
14949 |
|
| 334 |
|
| } |
| 335 |
|
| |
| 336 |
|
| void |
| 337 |
|
| pop_max(self) |
| 338 |
|
| SV *self |
| 339 |
|
| PREINIT: |
| 340 |
8836 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
8836 |
0 |
8836 |
| EXTRACT(self); |
0 |
8836 |
8836 |
| EXTRACT(self); |
0 |
8836 |
8836 |
|
| 341 |
|
| PPCODE: |
| 342 |
|
| { |
| 343 |
|
| int64_t m; double s; int ok; |
| 344 |
8836 |
▶ | if (h->readonly) croak("Data::SortedSet::Shared->pop_max: sorted set is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::SortedSet::Shared->pop_max: sorted set is frozen (read-only)"); |
2 |
8834 |
8836 |
|
| 345 |
8834 |
| ss_rwlock_wrlock(h); |
| 346 |
8834 |
▶ | if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->pop_max: sorted set is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->pop_max: sorted set is frozen (read-only)"); } |
0 |
8834 |
8834 |
|
| 347 |
8834 |
| ok = ss_pop_locked(h, 1, &m, &s); |
| 348 |
8834 |
▶ | if (ok) __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
Branch: 1 branch
| Branch | True | False | Total |
| if (ok) __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
8833 |
1 |
8834 |
|
| 349 |
8834 |
| ss_rwlock_wrunlock(h); |
| 350 |
8834 |
▶ | if (ok) { EXTEND(SP, 2); PUSHs(sv_2mortal(newSViv((IV)m))); PUSHs(sv_2mortal(newSVnv(s))); } |
Branch: 2 branches
| Branch | True | False | Total |
| if (ok) { EXTEND(SP, 2); PUSHs(sv_2mortal(newSViv((IV)m))); PUSHs(sv_2mortal(newSVnv(s))); } |
8833 |
1 |
8834 |
| if (ok) { EXTEND(SP, 2); PUSHs(sv_2mortal(newSViv((IV)m))); PUSHs(sv_2mortal(newSVnv(s))); } |
0 |
8833 |
8833 |
|
| 351 |
|
| } |
| 352 |
|
| |
| 353 |
|
| bool |
| 354 |
|
| _validate(self) |
| 355 |
|
| SV *self |
| 356 |
|
| PREINIT: |
| 357 |
107 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
107 |
0 |
107 |
| EXTRACT(self); |
0 |
107 |
107 |
| EXTRACT(self); |
0 |
107 |
107 |
|
| 358 |
|
| CODE: |
| 359 |
107 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
106 |
1 |
107 |
|
| 360 |
107 |
| RETVAL = ss_validate_tree(h); |
| 361 |
107 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
106 |
1 |
107 |
|
| 362 |
|
| OUTPUT: |
| 363 |
|
| RETVAL |
| 364 |
|
| |
| 365 |
|
| SV * |
| 366 |
|
| rank(self, member) |
| 367 |
|
| SV *self |
| 368 |
|
| IV member |
| 369 |
|
| PREINIT: |
| 370 |
9837 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
9837 |
0 |
9837 |
| EXTRACT(self); |
0 |
9837 |
9837 |
| EXTRACT(self); |
0 |
9837 |
9837 |
|
| 371 |
|
| double sc; |
| 372 |
|
| CODE: |
| 373 |
|
| { |
| 374 |
9837 |
| UV rk = 0; int found; |
| 375 |
9837 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
9834 |
3 |
9837 |
|
| 376 |
9837 |
| found = ss_idx_get(h, (int64_t)member, &sc); |
| 377 |
9837 |
▶ | if (found) rk = ss_rank_of(h, sc, (int64_t)member); |
Branch: 1 branch
| Branch | True | False | Total |
| if (found) rk = ss_rank_of(h, sc, (int64_t)member); |
9835 |
2 |
9837 |
|
| 378 |
9837 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
9834 |
3 |
9837 |
|
| 379 |
9837 |
▶ | RETVAL = found ? newSVuv(rk) : &PL_sv_undef; /* build SV after unlock: an OOM in newSVuv must not strand the read lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = found ? newSVuv(rk) : &PL_sv_undef; /* build SV after unlock: an OOM in newSVuv must not strand the read lock */ |
9835 |
2 |
9837 |
|
| 380 |
|
| } |
| 381 |
|
| OUTPUT: |
| 382 |
|
| RETVAL |
| 383 |
|
| |
| 384 |
|
| SV * |
| 385 |
|
| rev_rank(self, member) |
| 386 |
|
| SV *self |
| 387 |
|
| IV member |
| 388 |
|
| PREINIT: |
| 389 |
303 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
303 |
0 |
303 |
| EXTRACT(self); |
0 |
303 |
303 |
| EXTRACT(self); |
0 |
303 |
303 |
|
| 390 |
|
| double sc; |
| 391 |
|
| CODE: |
| 392 |
|
| { |
| 393 |
303 |
| UV rk = 0; int found; |
| 394 |
303 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
302 |
1 |
303 |
|
| 395 |
303 |
| found = ss_idx_get(h, (int64_t)member, &sc); |
| 396 |
303 |
▶ | if (found) rk = h->hdr->count - 1 - ss_rank_of(h, sc, (int64_t)member); |
Branch: 1 branch
| Branch | True | False | Total |
| if (found) rk = h->hdr->count - 1 - ss_rank_of(h, sc, (int64_t)member); |
303 |
0 |
303 |
|
| 397 |
303 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
302 |
1 |
303 |
|
| 398 |
303 |
▶ | RETVAL = found ? newSVuv(rk) : &PL_sv_undef; /* build SV after unlock */ |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = found ? newSVuv(rk) : &PL_sv_undef; /* build SV after unlock */ |
303 |
0 |
303 |
|
| 399 |
|
| } |
| 400 |
|
| OUTPUT: |
| 401 |
|
| RETVAL |
| 402 |
|
| |
| 403 |
|
| SV * |
| 404 |
|
| at_rank(self, rank) |
| 405 |
|
| SV *self |
| 406 |
|
| IV rank |
| 407 |
|
| PREINIT: |
| 408 |
311 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
311 |
0 |
311 |
| EXTRACT(self); |
0 |
311 |
311 |
| EXTRACT(self); |
0 |
311 |
311 |
|
| 409 |
|
| CODE: |
| 410 |
|
| { |
| 411 |
311 |
| IV val = 0; int found = 0; |
| 412 |
311 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
308 |
3 |
311 |
|
| 413 |
|
| { |
| 414 |
311 |
| uint32_t cnt = h->hdr->count; |
| 415 |
311 |
▶ | IV r = rank; if (r < 0) r += (IV)cnt; |
Branch: 1 branch
| Branch | True | False | Total |
| IV r = rank; if (r < 0) r += (IV)cnt; |
3 |
308 |
311 |
|
| 416 |
311 |
▶ | if (r >= 0 && (uint64_t)r < cnt) { /* compare in 64-bit; large r must not truncate to an in-range index */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (r >= 0 && (uint64_t)r < cnt) { /* compare in 64-bit; large r must not truncate to an in-range index */ |
311 |
0 |
311 |
| if (r >= 0 && (uint64_t)r < cnt) { /* compare in 64-bit; large r must not truncate to an in-range index */ |
307 |
4 |
311 |
|
| 417 |
307 |
| int pos; uint32_t leaf = ss_at_rank(h, (uint32_t)r, &pos); |
| 418 |
307 |
▶ | if (leaf != SS_NONE) { val = (IV)h->nodes[leaf].members[pos]; found = 1; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (leaf != SS_NONE) { val = (IV)h->nodes[leaf].members[pos]; found = 1; } |
307 |
0 |
307 |
|
| 419 |
|
| } |
| 420 |
|
| } |
| 421 |
311 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
308 |
3 |
311 |
|
| 422 |
311 |
▶ | RETVAL = found ? newSViv(val) : &PL_sv_undef; /* build SV after unlock */ |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = found ? newSViv(val) : &PL_sv_undef; /* build SV after unlock */ |
307 |
4 |
311 |
|
| 423 |
|
| } |
| 424 |
|
| OUTPUT: |
| 425 |
|
| RETVAL |
| 426 |
|
| |
| 427 |
|
| UV |
| 428 |
|
| count_in_score(self, min, max) |
| 429 |
|
| SV *self |
| 430 |
|
| NV min |
| 431 |
|
| NV max |
| 432 |
|
| PREINIT: |
| 433 |
42 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
42 |
0 |
42 |
| EXTRACT(self); |
0 |
42 |
42 |
| EXTRACT(self); |
0 |
42 |
42 |
|
| 434 |
|
| CODE: |
| 435 |
42 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
40 |
2 |
42 |
|
| 436 |
42 |
| RETVAL = ss_count_in_score(h, (double)min, (double)max, NULL); |
| 437 |
42 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
40 |
2 |
42 |
|
| 438 |
|
| OUTPUT: |
| 439 |
|
| RETVAL |
| 440 |
|
| |
| 441 |
|
| void |
| 442 |
|
| range_by_rank(self, start, stop, ...) |
| 443 |
|
| SV *self |
| 444 |
|
| IV start |
| 445 |
|
| IV stop |
| 446 |
|
| PREINIT: |
| 447 |
13 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
13 |
0 |
13 |
| EXTRACT(self); |
0 |
13 |
13 |
| EXTRACT(self); |
0 |
13 |
13 |
|
| 448 |
|
| PPCODE: |
| 449 |
13 |
| int ws = 0; |
| 450 |
13 |
| ss_parse_range_opts(aTHX_ &ST(0), 3, items, &ws, NULL, NULL); |
| 451 |
13 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
13 |
13 |
| REEXTRACT(self); |
0 |
13 |
13 |
|
| 452 |
13 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
11 |
2 |
13 |
|
| 453 |
|
| { |
| 454 |
13 |
| uint32_t s0 = 0, len = 0; |
| 455 |
|
| IV a, b; |
| 456 |
13 |
▶ | if (ss_rank_window(h->hdr->count, start, stop, &a, &b)) { s0 = (uint32_t)a; len = (uint32_t)(b - a + 1); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (ss_rank_window(h->hdr->count, start, stop, &a, &b)) { s0 = (uint32_t)a; len = (uint32_t)(b - a + 1); } |
11 |
2 |
13 |
|
| 457 |
2044 |
▶ | EMIT_COLLECTED(s0, len, 0, ws); |
Branch: 9 branches
| Branch | True | False | Total |
| EMIT_COLLECTED(s0, len, 0, ws); |
11 |
2 |
13 |
| EMIT_COLLECTED(s0, len, 0, ws); |
0 |
13 |
13 |
| EMIT_COLLECTED(s0, len, 0, ws); |
4 |
9 |
13 |
| EMIT_COLLECTED(s0, len, 0, ws); |
13 |
0 |
13 |
| EMIT_COLLECTED(s0, len, 0, ws); |
4 |
9 |
13 |
| EMIT_COLLECTED(s0, len, 0, ws); |
0 |
13 |
13 |
| EMIT_COLLECTED(s0, len, 0, ws); |
0 |
0 |
0 |
| EMIT_COLLECTED(s0, len, 0, ws); |
1008 |
1023 |
2031 |
| EMIT_COLLECTED(s0, len, 0, ws); |
2031 |
13 |
2044 |
|
| 458 |
|
| } |
| 459 |
|
| |
| 460 |
|
| void |
| 461 |
|
| rev_range_by_rank(self, start, stop, ...) |
| 462 |
|
| SV *self |
| 463 |
|
| IV start |
| 464 |
|
| IV stop |
| 465 |
|
| PREINIT: |
| 466 |
5 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
5 |
0 |
5 |
| EXTRACT(self); |
0 |
5 |
5 |
| EXTRACT(self); |
0 |
5 |
5 |
|
| 467 |
|
| PPCODE: |
| 468 |
5 |
| int ws = 0; |
| 469 |
5 |
| ss_parse_range_opts(aTHX_ &ST(0), 3, items, &ws, NULL, NULL); |
| 470 |
5 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
5 |
5 |
| REEXTRACT(self); |
0 |
5 |
5 |
|
| 471 |
5 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
4 |
1 |
5 |
|
| 472 |
|
| { |
| 473 |
5 |
| uint32_t cnt = h->hdr->count, s0 = 0, len = 0; |
| 474 |
|
| IV a, b; |
| 475 |
5 |
▶ | if (ss_rank_window(cnt, start, stop, &a, &b)) { s0 = (uint32_t)((IV)cnt - 1 - b); len = (uint32_t)(b - a + 1); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (ss_rank_window(cnt, start, stop, &a, &b)) { s0 = (uint32_t)((IV)cnt - 1 - b); len = (uint32_t)(b - a + 1); } |
5 |
0 |
5 |
|
| 476 |
1022 |
▶ | EMIT_COLLECTED(s0, len, 1, ws); |
Branch: 9 branches
| Branch | True | False | Total |
| EMIT_COLLECTED(s0, len, 1, ws); |
4 |
1 |
5 |
| EMIT_COLLECTED(s0, len, 1, ws); |
0 |
5 |
5 |
| EMIT_COLLECTED(s0, len, 1, ws); |
1 |
4 |
5 |
| EMIT_COLLECTED(s0, len, 1, ws); |
5 |
0 |
5 |
| EMIT_COLLECTED(s0, len, 1, ws); |
1 |
4 |
5 |
| EMIT_COLLECTED(s0, len, 1, ws); |
0 |
5 |
5 |
| EMIT_COLLECTED(s0, len, 1, ws); |
0 |
0 |
0 |
| EMIT_COLLECTED(s0, len, 1, ws); |
2 |
1015 |
1017 |
| EMIT_COLLECTED(s0, len, 1, ws); |
1017 |
5 |
1022 |
|
| 477 |
|
| } |
| 478 |
|
| |
| 479 |
|
| void |
| 480 |
|
| range_by_score(self, min, max, ...) |
| 481 |
|
| SV *self |
| 482 |
|
| NV min |
| 483 |
|
| NV max |
| 484 |
|
| PREINIT: |
| 485 |
43 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
43 |
0 |
43 |
| EXTRACT(self); |
0 |
43 |
43 |
| EXTRACT(self); |
0 |
43 |
43 |
|
| 486 |
|
| PPCODE: |
| 487 |
43 |
| int ws = 0; IV limit = -1, offset = 0; |
| 488 |
43 |
| ss_parse_range_opts(aTHX_ &ST(0), 3, items, &ws, &limit, &offset); |
| 489 |
43 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
43 |
43 |
| REEXTRACT(self); |
0 |
43 |
43 |
|
| 490 |
43 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
41 |
2 |
43 |
|
| 491 |
|
| { |
| 492 |
|
| uint32_t lo; |
| 493 |
43 |
| uint32_t win = ss_count_in_score(h, (double)min, (double)max, &lo); |
| 494 |
43 |
▶ | uint32_t off = (offset > 0) ? (offset >= (IV)win ? win : (uint32_t)offset) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| uint32_t off = (offset > 0) ? (offset >= (IV)win ? win : (uint32_t)offset) : 0; |
3 |
40 |
43 |
| uint32_t off = (offset > 0) ? (offset >= (IV)win ? win : (uint32_t)offset) : 0; |
2 |
1 |
3 |
|
| 495 |
43 |
| uint32_t s0 = lo, len = 0; |
| 496 |
43 |
▶ | if (off < win) { s0 = lo + off; len = win - off; if (limit >= 0 && limit < (IV)len) len = (uint32_t)limit; } |
Branch: 3 branches
| Branch | True | False | Total |
| if (off < win) { s0 = lo + off; len = win - off; if (limit >= 0 && limit < (IV)len) len = (uint32_t)limit; } |
40 |
3 |
43 |
| if (off < win) { s0 = lo + off; len = win - off; if (limit >= 0 && limit < (IV)len) len = (uint32_t)limit; } |
4 |
36 |
40 |
| if (off < win) { s0 = lo + off; len = win - off; if (limit >= 0 && limit < (IV)len) len = (uint32_t)limit; } |
3 |
1 |
4 |
|
| 497 |
43670 |
▶ | EMIT_COLLECTED(s0, len, 0, ws); |
Branch: 9 branches
| Branch | True | False | Total |
| EMIT_COLLECTED(s0, len, 0, ws); |
41 |
2 |
43 |
| EMIT_COLLECTED(s0, len, 0, ws); |
0 |
43 |
43 |
| EMIT_COLLECTED(s0, len, 0, ws); |
1 |
42 |
43 |
| EMIT_COLLECTED(s0, len, 0, ws); |
43 |
0 |
43 |
| EMIT_COLLECTED(s0, len, 0, ws); |
1 |
42 |
43 |
| EMIT_COLLECTED(s0, len, 0, ws); |
0 |
43 |
43 |
| EMIT_COLLECTED(s0, len, 0, ws); |
0 |
0 |
0 |
| EMIT_COLLECTED(s0, len, 0, ws); |
2 |
43625 |
43627 |
| EMIT_COLLECTED(s0, len, 0, ws); |
43627 |
43 |
43670 |
|
| 498 |
|
| } |
| 499 |
|
| |
| 500 |
|
| void |
| 501 |
|
| rev_range_by_score(self, max, min, ...) |
| 502 |
|
| SV *self |
| 503 |
|
| NV max |
| 504 |
|
| NV min |
| 505 |
|
| PREINIT: |
| 506 |
24 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
24 |
0 |
24 |
| EXTRACT(self); |
0 |
24 |
24 |
| EXTRACT(self); |
0 |
24 |
24 |
|
| 507 |
|
| PPCODE: |
| 508 |
24 |
| int ws = 0; IV limit = -1, offset = 0; |
| 509 |
24 |
| ss_parse_range_opts(aTHX_ &ST(0), 3, items, &ws, &limit, &offset); |
| 510 |
24 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
24 |
24 |
| REEXTRACT(self); |
0 |
24 |
24 |
|
| 511 |
24 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
23 |
1 |
24 |
|
| 512 |
|
| { |
| 513 |
|
| uint32_t lo; |
| 514 |
24 |
| uint32_t win = ss_count_in_score(h, (double)min, (double)max, &lo); |
| 515 |
24 |
▶ | uint32_t off = (offset > 0) ? (offset >= (IV)win ? win : (uint32_t)offset) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| uint32_t off = (offset > 0) ? (offset >= (IV)win ? win : (uint32_t)offset) : 0; |
2 |
22 |
24 |
| uint32_t off = (offset > 0) ? (offset >= (IV)win ? win : (uint32_t)offset) : 0; |
1 |
1 |
2 |
|
| 516 |
24 |
| uint32_t s0 = lo, len = 0; |
| 517 |
24 |
▶ | if (off < win) { len = win - off; if (limit >= 0 && limit < (IV)len) len = (uint32_t)limit; |
Branch: 3 branches
| Branch | True | False | Total |
| if (off < win) { len = win - off; if (limit >= 0 && limit < (IV)len) len = (uint32_t)limit; |
23 |
1 |
24 |
| if (off < win) { len = win - off; if (limit >= 0 && limit < (IV)len) len = (uint32_t)limit; |
1 |
22 |
23 |
| if (off < win) { len = win - off; if (limit >= 0 && limit < (IV)len) len = (uint32_t)limit; |
1 |
0 |
1 |
|
| 518 |
23 |
| s0 = lo + (win - off - len); } |
| 519 |
34354 |
▶ | EMIT_COLLECTED(s0, len, 1, ws); |
Branch: 9 branches
| Branch | True | False | Total |
| EMIT_COLLECTED(s0, len, 1, ws); |
23 |
1 |
24 |
| EMIT_COLLECTED(s0, len, 1, ws); |
0 |
24 |
24 |
| EMIT_COLLECTED(s0, len, 1, ws); |
0 |
24 |
24 |
| EMIT_COLLECTED(s0, len, 1, ws); |
24 |
0 |
24 |
| EMIT_COLLECTED(s0, len, 1, ws); |
0 |
24 |
24 |
| EMIT_COLLECTED(s0, len, 1, ws); |
0 |
24 |
24 |
| EMIT_COLLECTED(s0, len, 1, ws); |
0 |
0 |
0 |
| EMIT_COLLECTED(s0, len, 1, ws); |
0 |
34330 |
34330 |
| EMIT_COLLECTED(s0, len, 1, ws); |
34330 |
24 |
34354 |
|
| 520 |
|
| } |
| 521 |
|
| |
| 522 |
|
| void |
| 523 |
|
| peek_min(self) |
| 524 |
|
| SV *self |
| 525 |
|
| PREINIT: |
| 526 |
6 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
6 |
0 |
6 |
| EXTRACT(self); |
0 |
6 |
6 |
| EXTRACT(self); |
0 |
6 |
6 |
|
| 527 |
|
| PPCODE: |
| 528 |
6 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
5 |
1 |
6 |
|
| 529 |
6 |
▶ | if (h->hdr->root != SS_NONE && ss_node_ok(h, h->hdr->leftmost)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (h->hdr->root != SS_NONE && ss_node_ok(h, h->hdr->leftmost)) { |
5 |
1 |
6 |
| if (h->hdr->root != SS_NONE && ss_node_ok(h, h->hdr->leftmost)) { |
5 |
0 |
5 |
|
| 530 |
5 |
| SsNode *nd = &h->nodes[h->hdr->leftmost]; |
| 531 |
5 |
| IV m = (IV)nd->members[0]; NV s = nd->scores[0]; |
| 532 |
5 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
4 |
1 |
5 |
|
| 533 |
5 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
5 |
5 |
|
| 534 |
5 |
| PUSHs(sv_2mortal(newSViv(m))); |
| 535 |
5 |
| PUSHs(sv_2mortal(newSVnv(s))); |
| 536 |
1 |
▶ | } else if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (!h->readonly) ss_rwlock_rdunlock(h); |
1 |
0 |
1 |
|
| 537 |
|
| |
| 538 |
|
| void |
| 539 |
|
| peek_max(self) |
| 540 |
|
| SV *self |
| 541 |
|
| PREINIT: |
| 542 |
4 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
4 |
0 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
|
| 543 |
|
| PPCODE: |
| 544 |
4 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
3 |
1 |
4 |
|
| 545 |
4 |
▶ | if (h->hdr->root != SS_NONE && ss_node_ok(h, h->hdr->rightmost)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (h->hdr->root != SS_NONE && ss_node_ok(h, h->hdr->rightmost)) { |
4 |
0 |
4 |
| if (h->hdr->root != SS_NONE && ss_node_ok(h, h->hdr->rightmost)) { |
4 |
0 |
4 |
|
| 546 |
4 |
| SsNode *nd = &h->nodes[h->hdr->rightmost]; |
| 547 |
4 |
| IV m = (IV)nd->members[nd->num - 1]; NV s = nd->scores[nd->num - 1]; |
| 548 |
4 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
3 |
1 |
4 |
|
| 549 |
4 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
4 |
4 |
|
| 550 |
4 |
| PUSHs(sv_2mortal(newSViv(m))); |
| 551 |
4 |
| PUSHs(sv_2mortal(newSVnv(s))); |
| 552 |
0 |
▶ | } else if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (!h->readonly) ss_rwlock_rdunlock(h); |
0 |
0 |
0 |
|
| 553 |
|
| |
| 554 |
|
| void |
| 555 |
|
| each(self, cb) |
| 556 |
|
| SV *self |
| 557 |
|
| SV *cb |
| 558 |
|
| PREINIT: |
| 559 |
4 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
4 |
0 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
|
| 560 |
|
| CODE: |
| 561 |
4 |
▶ | SvGETMAGIC(cb); /* a tied/overloaded scalar may FETCH to a coderef */ |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(cb); /* a tied/overloaded scalar may FETCH to a coderef */ |
0 |
4 |
4 |
| SvGETMAGIC(cb); /* a tied/overloaded scalar may FETCH to a coderef */ |
0 |
0 |
0 |
|
| 562 |
4 |
▶ | if (!SvROK(cb) || SvTYPE(SvRV(cb)) != SVt_PVCV) croak("each: callback must be a code ref"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(cb) || SvTYPE(SvRV(cb)) != SVt_PVCV) croak("each: callback must be a code ref"); |
4 |
0 |
4 |
| if (!SvROK(cb) || SvTYPE(SvRV(cb)) != SVt_PVCV) croak("each: callback must be a code ref"); |
0 |
4 |
4 |
|
| 563 |
|
| { |
| 564 |
4 |
| ss_rcollect_t col = { NULL, NULL, 0, 0 }; |
| 565 |
4 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
4 |
4 |
| REEXTRACT(self); |
0 |
4 |
4 |
|
| 566 |
4 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
3 |
1 |
4 |
|
| 567 |
4 |
| int ok = ss_collect_range(h, 0, h->hdr->count, 0, &col); |
| 568 |
4 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
3 |
1 |
4 |
|
| 569 |
4 |
▶ | if (!ok) { free(col.members); free(col.scores); croak("each: out of memory"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ok) { free(col.members); free(col.scores); croak("each: out of memory"); } |
0 |
4 |
4 |
|
| 570 |
9951 |
▶ | for (size_t i = 0; i < col.n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < col.n; i++) { |
9948 |
3 |
9951 |
|
| 571 |
9948 |
▶ | dSP; ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| dSP; ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
9948 |
9948 |
|
| 572 |
9948 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)col.members[i]))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)col.members[i]))); |
0 |
9948 |
9948 |
|
| 573 |
9948 |
▶ | XPUSHs(sv_2mortal(newSVnv(col.scores[i]))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVnv(col.scores[i]))); |
0 |
9948 |
9948 |
|
| 574 |
9948 |
| PUTBACK; |
| 575 |
9948 |
| call_sv(cb, G_VOID|G_DISCARD|G_EVAL); |
| 576 |
9948 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
9948 |
0 |
9948 |
|
| 577 |
9948 |
▶ | if (SvTRUE(ERRSV)) { free(col.members); free(col.scores); croak_sv(ERRSV); } |
Branch: 3 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { free(col.members); free(col.scores); croak_sv(ERRSV); } |
9948 |
0 |
9948 |
| if (SvTRUE(ERRSV)) { free(col.members); free(col.scores); croak_sv(ERRSV); } |
1 |
9947 |
9948 |
| if (SvTRUE(ERRSV)) { free(col.members); free(col.scores); croak_sv(ERRSV); } |
1 |
0 |
1 |
|
| 578 |
|
| } |
| 579 |
3 |
| free(col.members); free(col.scores); |
| 580 |
|
| } |
| 581 |
|
| |
| 582 |
|
| void |
| 583 |
|
| _each_strings(self, keys, cb) |
| 584 |
|
| SV *self |
| 585 |
|
| SV *keys |
| 586 |
|
| SV *cb |
| 587 |
|
| PREINIT: |
| 588 |
5 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
5 |
0 |
5 |
| EXTRACT(self); |
0 |
5 |
5 |
| EXTRACT(self); |
0 |
5 |
5 |
|
| 589 |
|
| CODE: |
| 590 |
|
| { |
| 591 |
5 |
| ENTER; SAVETMPS; |
| 592 |
5 |
| SV *key_table = sv_2mortal(newSVsv(keys)); |
| 593 |
5 |
| SV *callback = sv_2mortal(newSVsv(cb)); |
| 594 |
5 |
▶ | if (!SvROK(callback) || SvTYPE(SvRV(callback)) != SVt_PVCV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(callback) || SvTYPE(SvRV(callback)) != SVt_PVCV) |
4 |
1 |
5 |
| if (!SvROK(callback) || SvTYPE(SvRV(callback)) != SVt_PVCV) |
0 |
4 |
4 |
|
| 595 |
1 |
| croak("each: callback must be a code ref"); |
| 596 |
4 |
▶ | if (!sv_isobject(key_table)) croak("each: expected a key table"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_isobject(key_table)) croak("each: expected a key table"); |
0 |
4 |
4 |
|
| 597 |
4 |
| GV *method = gv_fetchmethod(SvSTASH(SvRV(key_table)), "string"); |
| 598 |
4 |
▶ | if (!method || !GvCV(method)) croak("each: key table has no string method"); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!method || !GvCV(method)) croak("each: key table has no string method"); |
4 |
0 |
4 |
| if (!method || !GvCV(method)) croak("each: key table has no string method"); |
0 |
4 |
4 |
|
| 599 |
4 |
| SV *decode = sv_2mortal(SvREFCNT_inc((SV *)GvCV(method))); |
| 600 |
4 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
4 |
4 |
| REEXTRACT(self); |
0 |
4 |
4 |
|
| 601 |
|
| ss_rcollect_t *col; |
| 602 |
4 |
| Newxz(col, 1, ss_rcollect_t); |
| 603 |
4 |
| SAVEDESTRUCTOR_X(ss_free_snapshot, col); |
| 604 |
4 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); |
4 |
0 |
4 |
|
| 605 |
4 |
| int ok = ss_collect_range(h, 0, h->hdr->count, 0, col); |
| 606 |
4 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
4 |
0 |
4 |
|
| 607 |
4 |
▶ | if (!ok) croak("each: out of memory"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ok) croak("each: out of memory"); |
0 |
4 |
4 |
|
| 608 |
|
| SV **strings; |
| 609 |
4 |
▶ | Newx(strings, col->n, SV *); |
Branch: 1 branch
| Branch | True | False | Total |
| Newx(strings, col->n, SV *); |
0 |
4 |
4 |
|
| 610 |
4 |
| SAVEFREEPV(strings); |
| 611 |
890 |
▶ | for (size_t i = 0; i < col->n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < col->n; i++) { |
886 |
4 |
890 |
|
| 612 |
886 |
▶ | dSP; ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| dSP; ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
886 |
886 |
|
| 613 |
886 |
▶ | XPUSHs(key_table); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(key_table); |
0 |
886 |
886 |
|
| 614 |
886 |
▶ | XPUSHs(sv_2mortal(newSViv((IV)col->members[i]))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSViv((IV)col->members[i]))); |
0 |
886 |
886 |
|
| 615 |
886 |
| PUTBACK; |
| 616 |
886 |
| call_sv(decode, G_SCALAR); |
| 617 |
886 |
| SPAGAIN; |
| 618 |
886 |
| SV *str = POPs; |
| 619 |
886 |
| SvREFCNT_inc(str); |
| 620 |
886 |
| PUTBACK; |
| 621 |
886 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
886 |
0 |
886 |
|
| 622 |
886 |
| strings[i] = sv_2mortal(str); |
| 623 |
|
| } |
| 624 |
889 |
▶ | for (size_t i = 0; i < col->n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < col->n; i++) { |
886 |
3 |
889 |
|
| 625 |
886 |
▶ | dSP; ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| dSP; ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
886 |
886 |
|
| 626 |
886 |
▶ | XPUSHs(strings[i]); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(strings[i]); |
0 |
886 |
886 |
|
| 627 |
886 |
▶ | XPUSHs(sv_2mortal(newSVnv(col->scores[i]))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVnv(col->scores[i]))); |
0 |
886 |
886 |
|
| 628 |
886 |
| PUTBACK; |
| 629 |
886 |
| call_sv(callback, G_VOID|G_DISCARD); |
| 630 |
885 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
885 |
0 |
885 |
|
| 631 |
|
| } |
| 632 |
3 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
3 |
0 |
3 |
|
| 633 |
|
| } |
| 634 |
|
| |
| 635 |
|
| SV * |
| 636 |
|
| path(self) |
| 637 |
|
| SV *self |
| 638 |
|
| PREINIT: |
| 639 |
2 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
2 |
0 |
2 |
| EXTRACT(self); |
0 |
2 |
2 |
| EXTRACT(self); |
0 |
2 |
2 |
|
| 640 |
|
| CODE: |
| 641 |
2 |
▶ | RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->path ? newSVpv(h->path, 0) : &PL_sv_undef; |
1 |
1 |
2 |
|
| 642 |
|
| OUTPUT: |
| 643 |
|
| RETVAL |
| 644 |
|
| |
| 645 |
|
| int |
| 646 |
|
| memfd(self) |
| 647 |
|
| SV *self |
| 648 |
|
| PREINIT: |
| 649 |
1 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
1 |
0 |
1 |
| EXTRACT(self); |
0 |
1 |
1 |
| EXTRACT(self); |
0 |
1 |
1 |
|
| 650 |
|
| CODE: |
| 651 |
1 |
▶ | RETVAL = h->backing_fd; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->backing_fd; |
0 |
1 |
1 |
|
| 652 |
|
| OUTPUT: |
| 653 |
|
| RETVAL |
| 654 |
|
| |
| 655 |
|
| void |
| 656 |
|
| sync(self) |
| 657 |
|
| SV *self |
| 658 |
|
| PREINIT: |
| 659 |
6 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
6 |
0 |
6 |
| EXTRACT(self); |
0 |
6 |
6 |
| EXTRACT(self); |
0 |
6 |
6 |
|
| 660 |
|
| CODE: |
| 661 |
6 |
▶ | if (!h->readonly && ss_msync(h) != 0) croak("sync: %s", strerror(errno)); /* no-op on a read-only view */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!h->readonly && ss_msync(h) != 0) croak("sync: %s", strerror(errno)); /* no-op on a read-only view */ |
5 |
1 |
6 |
| if (!h->readonly && ss_msync(h) != 0) croak("sync: %s", strerror(errno)); /* no-op on a read-only view */ |
0 |
5 |
5 |
|
| 662 |
|
| |
| 663 |
|
| void |
| 664 |
|
| unlink(self, ...) |
| 665 |
|
| SV *self |
| 666 |
|
| CODE: |
| 667 |
|
| { |
| 668 |
2 |
| const char *p = NULL; |
| 669 |
3 |
▶ | if (sv_isobject(self) && sv_derived_from(self, "Data::SortedSet::Shared")) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (sv_isobject(self) && sv_derived_from(self, "Data::SortedSet::Shared")) { |
1 |
1 |
2 |
| if (sv_isobject(self) && sv_derived_from(self, "Data::SortedSet::Shared")) { |
1 |
0 |
1 |
|
| 670 |
1 |
| SsHandle *h = INT2PTR(SsHandle*, SvIV(SvRV(self))); |
| 671 |
1 |
▶ | if (h) p = h->path; |
Branch: 1 branch
| Branch | True | False | Total |
| if (h) p = h->path; |
1 |
0 |
1 |
|
| 672 |
1 |
▶ | } else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { |
Branch: 4 branches
| Branch | True | False | Total |
| } else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { |
1 |
0 |
1 |
| } else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { |
0 |
1 |
1 |
| } else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { |
0 |
0 |
0 |
| } else if (items >= 2 && (SvGETMAGIC(ST(1)), SvOK(ST(1)))) { |
1 |
0 |
1 |
|
| 673 |
2 |
| p = SvPV_nolen(ST(1)); |
| 674 |
|
| } |
| 675 |
2 |
▶ | if (p && unlink(p) != 0 && errno != ENOENT) croak("unlink: %s", strerror(errno)); |
Branch: 3 branches
| Branch | True | False | Total |
| if (p && unlink(p) != 0 && errno != ENOENT) croak("unlink: %s", strerror(errno)); |
2 |
0 |
2 |
| if (p && unlink(p) != 0 && errno != ENOENT) croak("unlink: %s", strerror(errno)); |
0 |
2 |
2 |
| if (p && unlink(p) != 0 && errno != ENOENT) croak("unlink: %s", strerror(errno)); |
0 |
0 |
0 |
|
| 676 |
|
| } |
| 677 |
|
| |
| 678 |
|
| int |
| 679 |
|
| eventfd(self) |
| 680 |
|
| SV *self |
| 681 |
|
| PREINIT: |
| 682 |
1 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
1 |
0 |
1 |
| EXTRACT(self); |
0 |
1 |
1 |
| EXTRACT(self); |
0 |
1 |
1 |
|
| 683 |
|
| CODE: |
| 684 |
1 |
| RETVAL = ss_create_eventfd(h); |
| 685 |
1 |
▶ | if (RETVAL < 0) croak("eventfd: %s", strerror(errno)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL < 0) croak("eventfd: %s", strerror(errno)); |
0 |
1 |
1 |
|
| 686 |
|
| OUTPUT: |
| 687 |
|
| RETVAL |
| 688 |
|
| |
| 689 |
|
| int |
| 690 |
|
| fileno(self) |
| 691 |
|
| SV *self |
| 692 |
|
| PREINIT: |
| 693 |
2 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
2 |
0 |
2 |
| EXTRACT(self); |
0 |
2 |
2 |
| EXTRACT(self); |
0 |
2 |
2 |
|
| 694 |
|
| CODE: |
| 695 |
2 |
▶ | RETVAL = h->notify_fd; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = h->notify_fd; |
0 |
2 |
2 |
|
| 696 |
|
| OUTPUT: |
| 697 |
|
| RETVAL |
| 698 |
|
| |
| 699 |
|
| bool |
| 700 |
|
| notify(self) |
| 701 |
|
| SV *self |
| 702 |
|
| PREINIT: |
| 703 |
1 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
1 |
0 |
1 |
| EXTRACT(self); |
0 |
1 |
1 |
| EXTRACT(self); |
0 |
1 |
1 |
|
| 704 |
|
| CODE: |
| 705 |
1 |
▶ | RETVAL = ss_notify(h); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ss_notify(h); |
1 |
0 |
1 |
|
| 706 |
|
| OUTPUT: |
| 707 |
|
| RETVAL |
| 708 |
|
| |
| 709 |
|
| SV * |
| 710 |
|
| eventfd_consume(self) |
| 711 |
|
| SV *self |
| 712 |
|
| PREINIT: |
| 713 |
1 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
1 |
0 |
1 |
| EXTRACT(self); |
0 |
1 |
1 |
| EXTRACT(self); |
0 |
1 |
1 |
|
| 714 |
|
| CODE: |
| 715 |
|
| { |
| 716 |
1 |
| int64_t v = ss_eventfd_consume(h); |
| 717 |
1 |
▶ | RETVAL = (v < 0) ? &PL_sv_undef : newSVuv((UV)v); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = (v < 0) ? &PL_sv_undef : newSVuv((UV)v); |
1 |
0 |
1 |
|
| 718 |
|
| } |
| 719 |
|
| OUTPUT: |
| 720 |
|
| RETVAL |
| 721 |
|
| |
| 722 |
|
| IV |
| 723 |
|
| add_many(self, rows) |
| 724 |
|
| SV *self |
| 725 |
|
| SV *rows |
| 726 |
|
| PREINIT: |
| 727 |
10 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
10 |
0 |
10 |
| EXTRACT(self); |
0 |
10 |
10 |
| EXTRACT(self); |
0 |
10 |
10 |
|
| 728 |
10 |
▶ | int added = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| int added = 0; |
10 |
0 |
10 |
|
| 729 |
|
| CODE: |
| 730 |
10 |
▶ | if (h->readonly) croak("Data::SortedSet::Shared->add_many: sorted set is frozen (read-only)"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->readonly) croak("Data::SortedSet::Shared->add_many: sorted set is frozen (read-only)"); |
2 |
8 |
10 |
|
| 731 |
8 |
▶ | SvGETMAGIC(rows); |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(rows); |
0 |
8 |
8 |
| SvGETMAGIC(rows); |
0 |
0 |
0 |
|
| 732 |
8 |
▶ | if (!SvROK(rows) || SvTYPE(SvRV(rows)) != SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(rows) || SvTYPE(SvRV(rows)) != SVt_PVAV) |
7 |
1 |
8 |
| if (!SvROK(rows) || SvTYPE(SvRV(rows)) != SVt_PVAV) |
0 |
7 |
7 |
|
| 733 |
1 |
| croak("add_many: expected an arrayref of [member, score] rows"); |
| 734 |
|
| { |
| 735 |
7 |
| AV *av = (AV *)SvRV(rows); |
| 736 |
|
| /* Pin the array for the whole resolve loop: an element's magic can |
| 737 |
|
| * drop the caller's last reference (undef $aref from an overload |
| 738 |
|
| * handler mutates ST(1) itself, because Perl passes aliases), freeing |
| 739 |
|
| * av and dangling every later av_fetch on it. */ |
| 740 |
7 |
| SvREFCNT_inc((SV *)av); sv_2mortal((SV *)av); |
| 741 |
7 |
| SSize_t nr = av_len(av) + 1; |
| 742 |
7 |
| int64_t *mem = NULL; |
| 743 |
7 |
| double *sco = NULL; |
| 744 |
7 |
| SSize_t n = 0; |
| 745 |
|
| /* Resolve ALL user-SV conversions (SvIV/SvNV run get-magic/overload = |
| 746 |
|
| * arbitrary Perl that can die/longjmp) into plain C arrays BEFORE taking |
| 747 |
|
| * the lock; inside the lock do ONLY pure C so a conversion can never |
| 748 |
|
| * abandon a held wrlock and permanently deadlock the mapping. */ |
| 749 |
7 |
▶ | if (nr > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (nr > 0) { |
7 |
0 |
7 |
|
| 750 |
7 |
▶ | Newx(mem, nr, int64_t); SAVEFREEPV(mem); /* freed on return OR a longjmp from SvNV/SvIV magic */ |
Branch: 1 branch
| Branch | True | False | Total |
| Newx(mem, nr, int64_t); SAVEFREEPV(mem); /* freed on return OR a longjmp from SvNV/SvIV magic */ |
0 |
7 |
7 |
|
| 751 |
7 |
▶ | Newx(sco, nr, double); SAVEFREEPV(sco); |
Branch: 1 branch
| Branch | True | False | Total |
| Newx(sco, nr, double); SAVEFREEPV(sco); |
0 |
7 |
7 |
|
| 752 |
3031 |
▶ | for (SSize_t i = 0; i < nr; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (SSize_t i = 0; i < nr; i++) { |
3024 |
7 |
3031 |
|
| 753 |
3024 |
| SV **rv = av_fetch(av, i, 0); |
| 754 |
3024 |
▶ | if (!rv) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!rv) continue; |
0 |
3024 |
3024 |
|
| 755 |
3024 |
| SV *rsv = *rv; |
| 756 |
3024 |
| SvREFCNT_inc(rsv); sv_2mortal(rsv); /* FETCH magic can drop the element from av */ |
| 757 |
3024 |
▶ | SvGETMAGIC(rsv); /* a tied-array element is a deferred-magic PVLV */ |
Branch: 2 branches
| Branch | True | False | Total |
| SvGETMAGIC(rsv); /* a tied-array element is a deferred-magic PVLV */ |
0 |
3024 |
3024 |
| SvGETMAGIC(rsv); /* a tied-array element is a deferred-magic PVLV */ |
0 |
0 |
0 |
|
| 758 |
3024 |
▶ | if (!SvROK(rsv) || SvTYPE(SvRV(rsv)) != SVt_PVAV) continue; /* skip malformed */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvROK(rsv) || SvTYPE(SvRV(rsv)) != SVt_PVAV) continue; /* skip malformed */ |
3023 |
1 |
3024 |
| if (!SvROK(rsv) || SvTYPE(SvRV(rsv)) != SVt_PVAV) continue; /* skip malformed */ |
0 |
3023 |
3023 |
|
| 759 |
3023 |
| AV *row = (AV *)SvRV(rsv); |
| 760 |
3023 |
| SvREFCNT_inc((SV *)row); sv_2mortal((SV *)row); /* element magic below can free the row AV */ |
| 761 |
3023 |
▶ | if (av_len(row) + 1 < 2) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(row) + 1 < 2) continue; |
2 |
3021 |
3023 |
|
| 762 |
3021 |
| SV **ms = av_fetch(row, 0, 0), **sv = av_fetch(row, 1, 0); |
| 763 |
3021 |
▶ | if (!ms || !sv) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!ms || !sv) continue; |
3021 |
0 |
3021 |
| if (!ms || !sv) continue; |
0 |
3021 |
3021 |
|
| 764 |
|
| /* Pin both element SVs by value BEFORE any magic runs: the |
| 765 |
|
| * score's SvNV can free or reassign the row AV, dangling the |
| 766 |
|
| * other's raw SV** slot. */ |
| 767 |
3021 |
| SV *memsv = *ms, *scosv = *sv; |
| 768 |
3021 |
| SvREFCNT_inc(memsv); sv_2mortal(memsv); |
| 769 |
3021 |
| SvREFCNT_inc(scosv); sv_2mortal(scosv); |
| 770 |
3021 |
| double score = SvNV(scosv); |
| 771 |
3021 |
▶ | if (score != score) continue; /* skip NaN */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (score != score) continue; /* skip NaN */ |
1 |
3020 |
3021 |
|
| 772 |
3020 |
| mem[n] = (int64_t)SvIV(memsv); |
| 773 |
3020 |
| sco[n] = score; |
| 774 |
3020 |
| n++; |
| 775 |
|
| } |
| 776 |
|
| } |
| 777 |
7 |
▶ | REEXTRACT(self); |
Branch: 2 branches
| Branch | True | False | Total |
| REEXTRACT(self); |
0 |
7 |
7 |
| REEXTRACT(self); |
0 |
7 |
7 |
|
| 778 |
7 |
| ss_rwlock_wrlock(h); |
| 779 |
7 |
▶ | if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->add_many: sorted set is frozen (read-only)"); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (h->hdr->sealed) { ss_rwlock_wrunlock(h); croak("Data::SortedSet::Shared->add_many: sorted set is frozen (read-only)"); } |
0 |
7 |
7 |
|
| 780 |
3025 |
▶ | for (SSize_t i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (SSize_t i = 0; i < n; i++) { |
3019 |
6 |
3025 |
|
| 781 |
3019 |
| int rc = ss_add_locked(h, mem[i], sco[i]); |
| 782 |
3019 |
▶ | if (rc == 1) added++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (rc == 1) added++; |
3016 |
3 |
3019 |
|
| 783 |
3 |
▶ | else if (rc == -1) break; /* pool full */ |
Branch: 1 branch
| Branch | True | False | Total |
| else if (rc == -1) break; /* pool full */ |
1 |
2 |
3 |
|
| 784 |
|
| } |
| 785 |
7 |
| __atomic_fetch_add(&h->hdr->stat_ops, 1, __ATOMIC_RELAXED); |
| 786 |
7 |
| ss_rwlock_wrunlock(h); |
| 787 |
|
| /* mem/sco freed by SAVEFREEPV at scope exit (croak-safe) */ |
| 788 |
|
| } |
| 789 |
7 |
▶ | RETVAL = added; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = added; |
2 |
5 |
7 |
|
| 790 |
|
| OUTPUT: |
| 791 |
|
| RETVAL |
| 792 |
|
| |
| 793 |
|
| SV * |
| 794 |
|
| stats(self) |
| 795 |
|
| SV *self |
| 796 |
|
| PREINIT: |
| 797 |
4 |
▶ | EXTRACT(self); |
Branch: 3 branches
| Branch | True | False | Total |
| EXTRACT(self); |
4 |
0 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
| EXTRACT(self); |
0 |
4 |
4 |
|
| 798 |
|
| CODE: |
| 799 |
|
| { |
| 800 |
|
| uint32_t count, max_entries, height, node_capacity, index_slots, nodes_used; |
| 801 |
|
| uint64_t ops; |
| 802 |
|
| /* Snapshot the header fields under the lock; do all (croak-capable) Perl |
| 803 |
|
| allocation after releasing it -- an OOM in newHV/newSVuv must never |
| 804 |
|
| strand the read lock. */ |
| 805 |
4 |
▶ | if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdlock(h); /* frozen: immutable, no lock */ |
3 |
1 |
4 |
|
| 806 |
4 |
| SsHeader *hd = h->hdr; |
| 807 |
4 |
| uint32_t nfree = 0, f = hd->node_free_head; |
| 808 |
|
| /* node_free_head / parent free-links are file-stored: bound the index and |
| 809 |
|
| cap iterations so a crafted out-of-range or cyclic free-list can't OOB |
| 810 |
|
| or spin (never taken for a valid free-list of length <= node_capacity) */ |
| 811 |
1737 |
▶ | while (f != SS_NONE && ss_node_ok(h, f) && nfree <= h->node_capacity) { nfree++; f = h->nodes[f].parent; } /* cached cap: trusted anti-spin bound */ |
Branch: 3 branches
| Branch | True | False | Total |
| while (f != SS_NONE && ss_node_ok(h, f) && nfree <= h->node_capacity) { nfree++; f = h->nodes[f].parent; } /* cached cap: trusted anti-spin bound */ |
1733 |
4 |
1737 |
| while (f != SS_NONE && ss_node_ok(h, f) && nfree <= h->node_capacity) { nfree++; f = h->nodes[f].parent; } /* cached cap: trusted anti-spin bound */ |
1733 |
0 |
1733 |
| while (f != SS_NONE && ss_node_ok(h, f) && nfree <= h->node_capacity) { nfree++; f = h->nodes[f].parent; } /* cached cap: trusted anti-spin bound */ |
1733 |
0 |
1733 |
|
| 812 |
4 |
| count = hd->count; /* backward-shift delete leaves no tombstones: occupied slots == count */ |
| 813 |
4 |
| max_entries = hd->max_entries; |
| 814 |
4 |
| height = hd->height; |
| 815 |
4 |
| node_capacity = hd->node_capacity; |
| 816 |
4 |
| index_slots = hd->index_slots; |
| 817 |
4 |
| nodes_used = hd->node_capacity - nfree; |
| 818 |
4 |
| ops = hd->stat_ops; |
| 819 |
4 |
▶ | if (!h->readonly) ss_rwlock_rdunlock(h); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!h->readonly) ss_rwlock_rdunlock(h); |
3 |
1 |
4 |
|
| 820 |
|
| |
| 821 |
4 |
| HV *hv = newHV(); |
| 822 |
4 |
| hv_stores(hv, "count", newSVuv(count)); |
| 823 |
4 |
| hv_stores(hv, "max_entries", newSVuv(max_entries)); |
| 824 |
4 |
| hv_stores(hv, "height", newSVuv(height)); |
| 825 |
4 |
| hv_stores(hv, "node_capacity", newSVuv(node_capacity)); |
| 826 |
4 |
| hv_stores(hv, "nodes_used", newSVuv(nodes_used)); |
| 827 |
4 |
| hv_stores(hv, "index_slots", newSVuv(index_slots)); |
| 828 |
4 |
| hv_stores(hv, "index_load", newSVnv((double)count / (double)index_slots)); |
| 829 |
4 |
| hv_stores(hv, "ops", newSVuv(ops)); |
| 830 |
4 |
| hv_stores(hv, "mmap_size", newSVuv((UV)h->mmap_size)); |
| 831 |
4 |
| hv_stores(hv, "frozen", newSVuv(h->hdr->sealed ? 1 : 0)); |
| 832 |
4 |
| hv_stores(hv, "readonly", newSVuv(h->readonly ? 1 : 0)); |
| 833 |
4 |
| RETVAL = newRV_noinc((SV *)hv); |
| 834 |
|
| } |
| 835 |
|
| OUTPUT: |
| 836 |
|
| RETVAL |