include/store/store_checkpoint.h

filter: Statementstmt 93.7% 30 / 32 Branchbran 81.2% 13 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 89.5% 43 / 48 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/store/store_history.h ↑ Summary xs/watch.xs »
1 #ifndef STORE_CHECKPOINT_H
2 #define STORE_CHECKPOINT_H
3  
4 /* Named checkpoints: a HAMT map from name to value. Naming one is one entry
5 * onto a value that already exists; it holds that value for as long as the
6 * name does, whatever the history limit drops. A name follows HAMT's key
7 * rule: the table makes the Latin-1 and the UTF-8 spelling of one string
8 * the same name. */
9  
10 /* A name from Perl: its bytes and whether they are UTF-8. */
11 240 static const char *store_name(pTHX_ SV *sv, STRLEN *len, int *utf8, const char *what) {
12 const char *p;
13 240 sv = store_read_once(aTHX_ sv);
14 240 ▶ if (!SvOK(sv)) croak("%s: a checkpoint's name cannot be undef", what);
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(sv)) croak("%s: a checkpoint's name cannot be undef", what); 1 239 240
15 239 p = SvPV(sv, *len);
16 239 *utf8 = SvUTF8(sv) ? 1 : 0;
17 239 return p;
18 }
19  
20 /* The value named, borrowed, or a croak naming the name. */
21 89 static SV *store_named(pTHX_ const store *s, SV *name, const char *what) {
22 STRLEN len;
23 int utf8;
24 89 const char *p = store_name(aTHX_ name, &len, &utf8, what);
25 89 ▶ SV *v = s->checkpoints ? (STORE_HAMT->map_fetch)(aTHX_ s->checkpoints, p, len, utf8) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *v = s->checkpoints ? (STORE_HAMT->map_fetch)(aTHX_ s->checkpoints, p, len, utf8) : NULL; 88 1 89
26 89 ▶ if (!v) croak("%s: no checkpoint named \"%" SVf "\"", what, SVfARG(name));
Branch: 1 branch
BranchTrueFalseTotal
if (!v) croak("%s: no checkpoint named \"%" SVf "\"", what, SVfARG(name)); 3 86 89
27 86 return v;
28 }
29  
30 82 static void store_checkpoint(pTHX_ store *s, SV *name, const char *what) {
31 STRLEN len;
32 int utf8;
33 const char *p;
34  
35 82 store_check_mutable(aTHX_ s, what);
36 81 p = store_name(aTHX_ name, &len, &utf8, what);
37 80 ▶ if (!s->checkpoints) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->checkpoints) { 65 15 80
38 65 s->checkpoints = (STORE_HAMT->map_new)(aTHX);
39 65 ▶ if (!s->checkpoints) croak("%s: out of memory", what);
Branch: 1 branch
BranchTrueFalseTotal
if (!s->checkpoints) croak("%s: out of memory", what); 0 65 65
40 }
41 80 ▶ if ((STORE_HAMT->map_store)(aTHX_ s->checkpoints, p, len, utf8, s->value) != HAMT_ABI_OK)
Branch: 1 branch
BranchTrueFalseTotal
if ((STORE_HAMT->map_store)(aTHX_ s->checkpoints, p, len, utf8, s->value) != HAMT_ABI_OK) 0 80 80
42 0 croak("%s: out of memory", what);
43 80 }
44  
45 58 static void store_drop_checkpoint(pTHX_ store *s, SV *name, const char *what) {
46 STRLEN len;
47 int utf8;
48 const char *p;
49  
50 58 store_check_mutable(aTHX_ s, what);
51 57 (void)store_named(aTHX_ s, name, what);
52 56 p = store_name(aTHX_ name, &len, &utf8, what);
53 56 ▶ if ((STORE_HAMT->map_remove)(aTHX_ s->checkpoints, p, len, utf8) != HAMT_ABI_OK)
Branch: 1 branch
BranchTrueFalseTotal
if ((STORE_HAMT->map_remove)(aTHX_ s->checkpoints, p, len, utf8) != HAMT_ABI_OK) 0 56 56
54 0 croak("%s: out of memory", what);
55 56 }
56  
57 20 static int store_name_into_av(pTHX_ void *ud, const char *key, STRLEN klen, int utf8, SV *value) {
58 20 SV *name = newSVpvn(key, klen);
59 PERL_UNUSED_ARG(value);
60 20 ▶ if (utf8) SvUTF8_on(name);
Branch: 1 branch
BranchTrueFalseTotal
if (utf8) SvUTF8_on(name); 2 18 20
61 20 av_push((AV *)ud, name);
62 20 return 0;
63 }
64  
65 #endif
« include/store/store_history.h ↑ Summary xs/watch.xs »