xs/history.xs

filter: Statementstmt 100% 41 / 41 Branchbran 86.1% 31 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 93.5% 72 / 77 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/watch.xs ↑ Summary xs/txn.xs »
1 # Undo and redo.
2  
3 MODULE = State::Store PACKAGE = State::Store
4  
5 # undo / redo, with an optional number of steps: how many were taken.
6 void
7 undo(self, ...)
8 SV *self
9 ALIAS:
10 redo = 1
11 PREINIT:
12 store *s;
13 size_t n;
14 const char *what;
15 SV *hold;
16 CODE:
17 51864 ▶ what = ix ? "State::Store::redo" : "State::Store::undo";
Branch: 1 branch
BranchTrueFalseTotal
what = ix ? "State::Store::redo" : "State::Store::undo"; 25749 26115 51864
18 51864 s = store_handle(aTHX_ self, what);
19 51864 ▶ if (items > 2) croak("%s: too many arguments", what);
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) croak("%s: too many arguments", what); 1 51863 51864
20 51863 ▶ n = store_steps(aTHX_ items > 1 ? ST(1) : NULL, what);
Branch: 1 branch
BranchTrueFalseTotal
n = store_steps(aTHX_ items > 1 ? ST(1) : NULL, what); 40605 11258 51863
21 51857 hold = sv_2mortal(newSVsv(self));
22 51857 n = store_move(aTHX_ s, !ix, n, what);
23 51853 store_deliver(aTHX_ s, hold);
24 51853 ST(0) = sv_2mortal(newSVuv((UV)n));
25 51853 XSRETURN(1);
26  
27 void
28 can_undo(self)
29 SV *self
30 ALIAS:
31 can_redo = 1
32 PREINIT:
33 store *s;
34 CODE:
35 6 ▶ s = store_handle(aTHX_ self, ix ? "State::Store::can_redo" : "State::Store::can_undo");
Branch: 1 branch
BranchTrueFalseTotal
s = store_handle(aTHX_ self, ix ? "State::Store::can_redo" : "State::Store::can_undo"); 3 3 6
36 6 ▶ ST(0) = boolSV((ix ? (STORE_HAMT->vec_count)(aTHX_ s->future) : store_past_len(aTHX_ s)) > 0);
Branch: 2 branches
BranchTrueFalseTotal
ST(0) = boolSV((ix ? (STORE_HAMT->vec_count)(aTHX_ s->future) : store_past_len(aTHX_ s)) > 0); 3 3 6
ST(0) = boolSV((ix ? (STORE_HAMT->vec_count)(aTHX_ s->future) : store_past_len(aTHX_ s)) > 0); 2 4 6
37 6 XSRETURN(1);
38  
39 void
40 undo_count(self)
41 SV *self
42 ALIAS:
43 redo_count = 1
44 PREINIT:
45 store *s;
46 CODE:
47 1080 ▶ s = store_handle(aTHX_ self, ix ? "State::Store::redo_count" : "State::Store::undo_count");
Branch: 1 branch
BranchTrueFalseTotal
s = store_handle(aTHX_ self, ix ? "State::Store::redo_count" : "State::Store::undo_count"); 520 560 1080
48 1080 ▶ ST(0) = sv_2mortal(newSVuv((UV)(ix ? (STORE_HAMT->vec_count)(aTHX_ s->future) : store_past_len(aTHX_ s))));
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = sv_2mortal(newSVuv((UV)(ix ? (STORE_HAMT->vec_count)(aTHX_ s->future) : store_past_len(aTHX_ s)))); 520 560 1080
49 1080 XSRETURN(1);
50  
51 void
52 clear_history(self)
53 SV *self
54 PREINIT:
55 store *s;
56 CODE:
57 2521 s = store_handle(aTHX_ self, "State::Store::clear_history");
58 2521 sv_2mortal(newSVsv(self));
59 2521 store_clear_history(aTHX_ s, "State::Store::clear_history");
60 2519 ST(0) = self;
61 2519 XSRETURN(1);
62  
63 # 0 when both stacks are well formed vectors, or the number of the first
64 # check that failed: 1 for the past, 2 for the future. For the tests.
65 IV
66 _check(self)
67 SV *self
68 PREINIT:
69 store *s;
70 CODE:
71 711 s = store_handle(aTHX_ self, "State::Store::_check");
72 1422 ▶ RETVAL = (STORE_HAMT->vec_check)(aTHX_ s->past) ? 1
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (STORE_HAMT->vec_check)(aTHX_ s->past) ? 1 706 5 711
73 711 ▶ : (STORE_HAMT->vec_check)(aTHX_ s->future) ? 2 : 0;
Branch: 2 branches
BranchTrueFalseTotal
: (STORE_HAMT->vec_check)(aTHX_ s->future) ? 2 : 0; 711 0 711
: (STORE_HAMT->vec_check)(aTHX_ s->future) ? 2 : 0; 0 711 711
74 OUTPUT:
75 RETVAL
76  
77 # Both stacks as lists, past then future, for a test to compare with a model:
78 # the past as undo sees it, without steps beyond the limit not yet cut.
79 void
80 _stacks(self)
81 SV *self
82 PREINIT:
83 store *s;
84 AV *past, *future;
85 PPCODE:
86 259 s = store_handle(aTHX_ self, "State::Store::_stacks");
87 259 past = (STORE_HAMT->vec_to_av)(aTHX_ s->past);
88 259 future = (STORE_HAMT->vec_to_av)(aTHX_ s->future);
89 259 ▶ if (!past || !future) croak("State::Store::_stacks: out of memory");
Branch: 2 branches
BranchTrueFalseTotal
if (!past || !future) croak("State::Store::_stacks: out of memory"); 259 0 259
if (!past || !future) croak("State::Store::_stacks: out of memory"); 0 259 259
90 883 ▶ while ((size_t)(av_len(past) + 1) > store_past_len(aTHX_ s)) SvREFCNT_dec(av_shift(past));
Branch: 1 branch
BranchTrueFalseTotal
while ((size_t)(av_len(past) + 1) > store_past_len(aTHX_ s)) SvREFCNT_dec(av_shift(past)); 624 259 883
91 259 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 259 259
92 259 PUSHs(sv_2mortal(newRV_noinc((SV *)past)));
93 259 PUSHs(sv_2mortal(newRV_noinc((SV *)future)));
94  
95 # history_limit: the limit, or undef for none. With an argument, sets it,
96 # cuts the past to it at once, and returns the store.
97 void
98 history_limit(self, ...)
99 SV *self
100 PREINIT:
101 store *s;
102 size_t limit;
103 int limited;
104 CODE:
105 31 s = store_handle(aTHX_ self, "State::Store::history_limit");
106 31 ▶ if (items > 2) croak("State::Store::history_limit: too many arguments");
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) croak("State::Store::history_limit: too many arguments"); 1 30 31
107 30 ▶ if (items == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) { 14 16 30
108 14 ▶ ST(0) = s->limited ? sv_2mortal(newSVuv((UV)s->limit)) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = s->limited ? sv_2mortal(newSVuv((UV)s->limit)) : &PL_sv_undef; 11 3 14
109 14 XSRETURN(1);
110 }
111 16 store_limit_arg(aTHX_ ST(1), &limit, &limited, "State::Store::history_limit");
112 11 sv_2mortal(newSVsv(self));
113 11 store_set_limit(aTHX_ s, limit, limited, "State::Store::history_limit");
114 9 ST(0) = self;
115 9 XSRETURN(1);
« xs/watch.xs ↑ Summary xs/txn.xs »