| 1 |
|
| # HAMT::Vector::Transient: a vector opened for a batch of updates. |
| 2 |
|
| |
| 3 |
|
| MODULE = HAMT PACKAGE = HAMT::Vector::Transient |
| 4 |
|
| |
| 5 |
|
| void |
| 6 |
|
| push(self, ...) |
| 7 |
|
| SV *self |
| 8 |
|
| PREINIT: |
| 9 |
|
| hamt_vtxn *t; |
| 10 |
|
| I32 i; |
| 11 |
|
| CODE: |
| 12 |
82632 |
| t = hamt_vtxn_handle(aTHX_ self, "HAMT::Vector::Transient::push"); |
| 13 |
165263 |
▶ | for (i = 1; i < items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < items; i++) { |
82632 |
82631 |
165263 |
|
| 14 |
82632 |
| hamt_xs_vec_push(aTHX_ &t->v, ST(i), "HAMT::Vector::Transient::push"); |
| 15 |
|
| /* Reading a value can run Perl, and Perl can close the transient. */ |
| 16 |
82632 |
| t = hamt_vtxn_handle(aTHX_ self, "HAMT::Vector::Transient::push"); |
| 17 |
|
| } |
| 18 |
82631 |
| XSRETURN(1); |
| 19 |
|
| |
| 20 |
|
| void |
| 21 |
|
| set(self, index, value) |
| 22 |
|
| SV *self |
| 23 |
|
| SV *index |
| 24 |
|
| SV *value |
| 25 |
|
| PREINIT: |
| 26 |
|
| hamt_vtxn *t; |
| 27 |
|
| size_t i; |
| 28 |
|
| CODE: |
| 29 |
15060 |
| t = hamt_vtxn_handle(aTHX_ self, "HAMT::Vector::Transient::set"); |
| 30 |
15059 |
▶ | if (!hamt_xs_index(aTHX_ index, t->v.count, &i)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!hamt_xs_index(aTHX_ index, t->v.count, &i)) |
1 |
15058 |
15059 |
|
| 31 |
1 |
| croak("HAMT::Vector::Transient::set: index %" IVdf " is out of range for %" UVuf " elements", |
| 32 |
|
| SvIV(index), (UV)t->v.count); |
| 33 |
15058 |
| hamt_xs_vec_set(aTHX_ &t->v, i, value, "HAMT::Vector::Transient::set"); |
| 34 |
15058 |
| XSRETURN(1); |
| 35 |
|
| |
| 36 |
|
| void |
| 37 |
|
| pop(self) |
| 38 |
|
| SV *self |
| 39 |
|
| PREINIT: |
| 40 |
|
| hamt_vtxn *t; |
| 41 |
|
| CODE: |
| 42 |
62925 |
| t = hamt_vtxn_handle(aTHX_ self, "HAMT::Vector::Transient::pop"); |
| 43 |
62924 |
| hamt_xs_vec_pop(aTHX_ &t->v, "HAMT::Vector::Transient::pop"); |
| 44 |
62924 |
| XSRETURN(1); |
| 45 |
|
| |
| 46 |
|
| void |
| 47 |
|
| get(self, index) |
| 48 |
|
| SV *self |
| 49 |
|
| SV *index |
| 50 |
|
| PREINIT: |
| 51 |
|
| hamt_vtxn *t; |
| 52 |
|
| size_t i; |
| 53 |
|
| CODE: |
| 54 |
5073 |
| t = hamt_vtxn_handle(aTHX_ self, "HAMT::Vector::Transient::get"); |
| 55 |
5072 |
| ST(0) = hamt_xs_index(aTHX_ index, t->v.count, &i) |
| 56 |
5054 |
| ? sv_2mortal(SvREFCNT_inc_simple_NN((SV *)hamt_vec_get(&t->v, i))) |
| 57 |
5072 |
▶ | : sv_newmortal(); |
Branch: 1 branch
| Branch | True | False | Total |
| : sv_newmortal(); |
5054 |
18 |
5072 |
|
| 58 |
5072 |
| XSRETURN(1); |
| 59 |
|
| |
| 60 |
|
| void |
| 61 |
|
| count(self) |
| 62 |
|
| SV *self |
| 63 |
|
| PREINIT: |
| 64 |
|
| hamt_vtxn *t; |
| 65 |
|
| CODE: |
| 66 |
100009 |
| t = hamt_vtxn_handle(aTHX_ self, "HAMT::Vector::Transient::count"); |
| 67 |
100007 |
| ST(0) = sv_2mortal(newSVuv((UV)t->v.count)); |
| 68 |
100007 |
| XSRETURN(1); |
| 69 |
|
| |
| 70 |
|
| # An ordinary vector of what the transient holds, of the class it was opened |
| 71 |
|
| # from. The transient is closed, and holds nothing afterwards. |
| 72 |
|
| void |
| 73 |
|
| persistent(self) |
| 74 |
|
| SV *self |
| 75 |
|
| PREINIT: |
| 76 |
|
| hamt_vtxn *t; |
| 77 |
|
| hamt_vec *n, gone; |
| 78 |
|
| HV *origin; |
| 79 |
|
| SV *obj; |
| 80 |
|
| CODE: |
| 81 |
300 |
| t = hamt_vtxn_handle(aTHX_ self, "HAMT::Vector::Transient::persistent"); |
| 82 |
299 |
| obj = hamt_vec_handle_new(aTHX_ t->origin, &t->v, &n, |
| 83 |
|
| "HAMT::Vector::Transient::persistent"); |
| 84 |
299 |
| gone = t->v; |
| 85 |
299 |
| origin = t->origin; |
| 86 |
299 |
| t->open = 0; |
| 87 |
299 |
| t->origin = NULL; |
| 88 |
299 |
| hamt_vec_init(&t->v); |
| 89 |
299 |
| SvREFCNT_dec((SV *)origin); |
| 90 |
299 |
| hamt_vec_clear(HAMT_CX, &gone); |
| 91 |
299 |
| ST(0) = obj; |
| 92 |
299 |
| XSRETURN(1); |
| 93 |
|
| |
| 94 |
|
| void |
| 95 |
|
| _check(self) |
| 96 |
|
| SV *self |
| 97 |
|
| PREINIT: |
| 98 |
|
| hamt_vtxn *t; |
| 99 |
|
| CODE: |
| 100 |
3 |
| t = hamt_vtxn_handle(aTHX_ self, "HAMT::Vector::Transient::_check"); |
| 101 |
3 |
| ST(0) = sv_2mortal(newSViv((IV)hamt_vec_check(&t->v))); |
| 102 |
3 |
| XSRETURN(1); |
| 103 |
|
| |
| 104 |
|
| void |
| 105 |
|
| CLONE_SKIP(...) |
| 106 |
|
| CODE: |
| 107 |
0 |
| ST(0) = &PL_sv_yes; |
| 108 |
0 |
| XSRETURN(1); |