xs/checkpoint.xs

filter: Statementstmt 100% 31 / 31 Branchbran 83.3% 15 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 93.8% 46 / 49 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/txn.xs ↑ Summary include/store/store_watch.h »
1 # Named checkpoints.
2  
3 MODULE = State::Store PACKAGE = State::Store
4  
5 # checkpoint($name): the current value under that name. Returns the store.
6 void
7 checkpoint(self, name)
8 SV *self
9 SV *name
10 CODE:
11 31 store_checkpoint(aTHX_ store_handle(aTHX_ self, "State::Store::checkpoint"),
12 name, "State::Store::checkpoint");
13 29 ST(0) = self;
14 29 XSRETURN(1);
15  
16 # restore($name): the value named becomes current, as a change: a step, the
17 # redo stack emptied, the watchers told; not the validator. Returns the store.
18 void
19 restore(self, name)
20 SV *self
21 SV *name
22 PREINIT:
23 store *s;
24 SV *hold, *value;
25 CODE:
26 19 s = store_handle(aTHX_ self, "State::Store::restore");
27 19 store_check_mutable(aTHX_ s, "State::Store::restore");
28 18 store_check_no_txn(aTHX_ s, "State::Store::restore");
29 17 hold = sv_2mortal(newSVsv(self));
30 17 value = sv_2mortal(SvREFCNT_inc_simple_NN(store_named(aTHX_ s, name, "State::Store::restore")));
31 15 store_put(aTHX_ s, value, hold, 0, "State::Store::restore");
32 15 store_deliver(aTHX_ s, hold);
33 15 ST(0) = self;
34 15 XSRETURN(1);
35  
36 void
37 has_checkpoint(self, name)
38 SV *self
39 SV *name
40 PREINIT:
41 store *s;
42 STRLEN len;
43 int utf8;
44 const char *p;
45 CODE:
46 14 s = store_handle(aTHX_ self, "State::Store::has_checkpoint");
47 14 p = store_name(aTHX_ name, &len, &utf8, "State::Store::has_checkpoint");
48 14 ▶ ST(0) = boolSV(s->checkpoints && (STORE_HAMT->map_has)(aTHX_ s->checkpoints, p, len, utf8));
Branch: 2 branches
BranchTrueFalseTotal
ST(0) = boolSV(s->checkpoints && (STORE_HAMT->map_has)(aTHX_ s->checkpoints, p, len, utf8)); 13 1 14
ST(0) = boolSV(s->checkpoints && (STORE_HAMT->map_has)(aTHX_ s->checkpoints, p, len, utf8)); 10 3 13
49 14 XSRETURN(1);
50  
51 void
52 drop_checkpoint(self, name)
53 SV *self
54 SV *name
55 CODE:
56 7 sv_2mortal(newSVsv(self));
57 7 store_drop_checkpoint(aTHX_ store_handle(aTHX_ self, "State::Store::drop_checkpoint"),
58 name, "State::Store::drop_checkpoint");
59 5 ST(0) = self;
60 5 XSRETURN(1);
61  
62 # The names, sorted; in scalar context, how many.
63 void
64 checkpoints(self)
65 SV *self
66 PREINIT:
67 store *s;
68 AV *names;
69 SSize_t i, n;
70 PPCODE:
71 12 s = store_handle(aTHX_ self, "State::Store::checkpoints");
72 12 ▶ n = s->checkpoints ? (SSize_t)(STORE_HAMT->map_count)(aTHX_ s->checkpoints) : 0;
Branch: 1 branch
BranchTrueFalseTotal
n = s->checkpoints ? (SSize_t)(STORE_HAMT->map_count)(aTHX_ s->checkpoints) : 0; 10 2 12
73 12 ▶ if (GIMME_V != G_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_LIST) { 4 8 12
74 4 ▶ XPUSHs(sv_2mortal(newSVuv((UV)n)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVuv((UV)n))); 0 4 4
75 4 XSRETURN(1);
76 }
77 8 ▶ if (!n) XSRETURN_EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
if (!n) XSRETURN_EMPTY; 1 7 8
78 7 names = (AV *)sv_2mortal((SV *)newAV());
79 7 (STORE_HAMT->map_walk)(aTHX_ s->checkpoints, store_name_into_av, names);
80 7 sortsv(AvARRAY(names), av_len(names) + 1, Perl_sv_cmp);
81 7 ▶ EXTEND(SP, n);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, n); 7 0 7
EXTEND(SP, n); 0 7 7
82 27 ▶ for (i = 0; i < n; i++) PUSHs(*av_fetch(names, i, 0));
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) PUSHs(*av_fetch(names, i, 0)); 20 7 27
« xs/txn.xs ↑ Summary include/store/store_watch.h »