line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
namespace xs { |
4
|
|
|
|
|
|
|
|
5
|
13
|
|
|
|
|
|
Array Array::create (size_t size, SV** content, create_type_t type) { |
6
|
13
|
|
|
|
|
|
Array ret = create(); |
7
|
13
|
50
|
|
|
|
|
ret.resize(size); |
8
|
13
|
|
|
|
|
|
SV** dst = ret._svlist(); |
9
|
|
|
|
|
|
|
|
10
|
13
|
100
|
|
|
|
|
if (type == COPY) { |
11
|
5
|
100
|
|
|
|
|
for (size_t i = 0; i < size; ++i) { |
12
|
3
|
50
|
|
|
|
|
if (*content) { |
13
|
3
|
50
|
|
|
|
|
SV* val = *dst++ = newSV(0); |
14
|
3
|
50
|
|
|
|
|
sv_setsv_flags(val, *content++, SV_DO_COW_SVSETSV|SV_NOSTEAL); |
15
|
|
|
|
|
|
|
} else { |
16
|
0
|
|
|
|
|
|
++content; |
17
|
0
|
|
|
|
|
|
++dst; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} else { |
21
|
30
|
100
|
|
|
|
|
for (size_t i = 0; i < size; ++i) *dst++ = SvREFCNT_inc(*content++); |
22
|
|
|
|
|
|
|
} |
23
|
13
|
|
|
|
|
|
return ret; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
16
|
|
|
|
|
|
Array::Array (const std::initializer_list& l, create_type_t type) { |
27
|
8
|
|
|
|
|
|
SV* svs[l.size()]; |
28
|
8
|
|
|
|
|
|
const Scalar* from = l.begin(); |
29
|
23
|
100
|
|
|
|
|
for (size_t i = 0; i < l.size(); ++i) svs[i] = (*from++).get(); |
30
|
16
|
50
|
|
|
|
|
auto tmp = create(l.size(), svs, type); |
31
|
8
|
|
|
|
|
|
*this = std::move(tmp); |
32
|
8
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
18
|
|
|
|
|
|
void Array::store (size_t key, const Scalar& val) { |
35
|
18
|
100
|
|
|
|
|
if (!sv) throw std::logic_error("store: empty object"); |
|
|
50
|
|
|
|
|
|
36
|
17
|
100
|
|
|
|
|
SvREFCNT_inc_simple_void(val.get()); |
37
|
|
|
|
|
|
|
|
38
|
17
|
100
|
|
|
|
|
if (key >= _cap()) av_extend((AV*)sv, key); |
|
|
50
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
17
|
|
|
|
|
|
auto ptr = _svlist() + key; |
41
|
17
|
|
|
|
|
|
auto old = *ptr; |
42
|
17
|
|
|
|
|
|
*ptr = val.get(); |
43
|
|
|
|
|
|
|
|
44
|
17
|
50
|
|
|
|
|
if (_size() <= key) _size(key+1); |
|
|
100
|
|
|
|
|
|
45
|
9
|
50
|
|
|
|
|
else SvREFCNT_dec(old); |
46
|
17
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
|
void Array::push (const std::initializer_list& l) { |
49
|
5
|
|
|
|
|
|
auto oldsize = size(); |
50
|
5
|
|
|
|
|
|
auto addsize = l.size(); |
51
|
5
|
|
|
|
|
|
resize(oldsize + addsize); |
52
|
5
|
|
|
|
|
|
const Scalar* from = l.begin(); |
53
|
5
|
|
|
|
|
|
SV** dst = _svlist() + oldsize; |
54
|
18
|
100
|
|
|
|
|
for (size_t i = 0; i < addsize; ++i) *dst++ = SvREFCNT_inc((from++)->get()); |
55
|
5
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
|
void Array::push (const List& l) { |
58
|
1
|
|
|
|
|
|
auto oldsize = size(); |
59
|
1
|
|
|
|
|
|
auto addsize = l.size(); |
60
|
1
|
|
|
|
|
|
resize(oldsize + addsize); |
61
|
1
|
|
|
|
|
|
SV** from = l._svlist(); |
62
|
1
|
|
|
|
|
|
SV** dst = _svlist() + oldsize; |
63
|
3
|
100
|
|
|
|
|
for (size_t i = 0; i < addsize; ++i) *dst++ = SvREFCNT_inc(*from++); |
64
|
1
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
11
|
|
|
|
|
|
void Array::push (const Scalar& v) { |
67
|
11
|
|
|
|
|
|
auto oldsize = size(); |
68
|
11
|
|
|
|
|
|
resize(oldsize + 1); |
69
|
11
|
|
|
|
|
|
_svlist()[oldsize] = SvREFCNT_inc(v.get()); |
70
|
11
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
|
void Array::unshift (const std::initializer_list& l) { |
73
|
1
|
|
|
|
|
|
auto addsize = l.size(); |
74
|
1
|
|
|
|
|
|
av_unshift((AV*)sv, addsize); |
75
|
1
|
|
|
|
|
|
const Scalar* from = l.begin(); |
76
|
1
|
|
|
|
|
|
SV** dst = _svlist(); |
77
|
4
|
100
|
|
|
|
|
for (size_t i = 0; i < addsize; ++i) *dst++ = SvREFCNT_inc((from++)->get()); |
78
|
1
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
|
void Array::unshift (const List& l) { |
81
|
1
|
|
|
|
|
|
auto addsize = l.size(); |
82
|
1
|
|
|
|
|
|
av_unshift((AV*)sv, addsize); |
83
|
1
|
|
|
|
|
|
SV** from = l._svlist(); |
84
|
1
|
|
|
|
|
|
SV** dst = _svlist(); |
85
|
3
|
100
|
|
|
|
|
for (size_t i = 0; i < addsize; ++i) *dst++ = SvREFCNT_inc(*from++); |
86
|
1
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
3
|
|
|
|
|
|
void Array::unshift (const Scalar& v) { |
89
|
3
|
|
|
|
|
|
av_unshift((AV*)sv, 1); |
90
|
3
|
|
|
|
|
|
*(_svlist()) = SvREFCNT_inc(v.get()); |
91
|
3
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
|
|
|
U32 Array::push_on_stack (SV** sp, U32 max) const { |
94
|
1
|
|
|
|
|
|
auto sz = size(); |
95
|
1
|
50
|
|
|
|
|
if (max && sz > max) sz = max; |
|
|
0
|
|
|
|
|
|
96
|
1
|
50
|
|
|
|
|
EXTEND(sp, (I32)sz); |
|
|
50
|
|
|
|
|
|
97
|
1
|
|
|
|
|
|
SV** list = _svlist(); |
98
|
4
|
100
|
|
|
|
|
for (decltype(sz) i = 0; i < sz; ++i) *++sp = sv_2mortal(SvREFCNT_inc(list[i])); |
99
|
1
|
|
|
|
|
|
return sz; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |