line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBM::Deep::Array; |
2
|
|
|
|
|
|
|
|
3
|
20
|
|
|
20
|
|
469
|
use 5.008_004; |
|
20
|
|
|
|
|
67
|
|
4
|
|
|
|
|
|
|
|
5
|
20
|
|
|
20
|
|
131
|
use strict; |
|
20
|
|
|
|
|
38
|
|
|
20
|
|
|
|
|
668
|
|
6
|
20
|
|
|
20
|
|
160
|
use warnings FATAL => 'all'; |
|
20
|
|
|
|
|
43
|
|
|
20
|
|
|
|
|
940
|
|
7
|
20
|
|
|
20
|
|
125
|
no warnings 'recursion'; |
|
20
|
|
|
|
|
35
|
|
|
20
|
|
|
|
|
1384
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# This is to allow DBM::Deep::Array to handle negative indices on |
10
|
|
|
|
|
|
|
# its own. Otherwise, Perl would intercept the call to negative |
11
|
|
|
|
|
|
|
# indices for us. This was causing bugs for negative index handling. |
12
|
|
|
|
|
|
|
our $NEGATIVE_INDICES = 1; |
13
|
|
|
|
|
|
|
|
14
|
20
|
|
|
20
|
|
149
|
use base 'DBM::Deep'; |
|
20
|
|
|
|
|
39
|
|
|
20
|
|
|
|
|
1867
|
|
15
|
|
|
|
|
|
|
|
16
|
20
|
|
|
20
|
|
198
|
use Scalar::Util (); |
|
20
|
|
|
|
|
43
|
|
|
20
|
|
|
|
|
47257
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _get_self { |
19
|
|
|
|
|
|
|
# We used to have |
20
|
|
|
|
|
|
|
# eval { local $SIG{'__DIE__'}; tied( @{$_[0]} ) } || $_[0] |
21
|
|
|
|
|
|
|
# but this does not always work during global destruction (DBM::Deep’s |
22
|
|
|
|
|
|
|
# destructor calls this method), but will return $_[0] even when $_[0] |
23
|
|
|
|
|
|
|
# is tied, if it’s tied to undef. In those cases it’s better to return |
24
|
|
|
|
|
|
|
# undef, so the destructor can tell not to do anything, and, if any- |
25
|
|
|
|
|
|
|
# thing else calls us, it will fail with a more helpful error message. |
26
|
|
|
|
|
|
|
|
27
|
37823
|
100
|
|
37823
|
|
99692
|
Scalar::Util::reftype $_[0] eq 'ARRAY' ? tied @{$_[0]} : $_[0]; |
|
3218
|
|
|
|
|
8611
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
23
|
|
|
23
|
|
54
|
sub _repr { [] } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub TIEARRAY { |
33
|
2160
|
|
|
2160
|
|
4296
|
my $class = shift; |
34
|
2160
|
|
|
|
|
5998
|
my $args = $class->_get_args( @_ ); |
35
|
|
|
|
|
|
|
|
36
|
2158
|
|
|
|
|
5386
|
$args->{type} = $class->TYPE_ARRAY; |
37
|
|
|
|
|
|
|
|
38
|
2158
|
|
|
|
|
6336
|
return $class->_init($args); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub FETCH { |
42
|
520
|
|
|
520
|
|
16391
|
my $self = shift->_get_self; |
43
|
520
|
|
|
|
|
1077
|
my ($key) = @_; |
44
|
|
|
|
|
|
|
|
45
|
520
|
|
|
|
|
1396
|
$self->lock_shared; |
46
|
|
|
|
|
|
|
|
47
|
520
|
100
|
|
|
|
3989
|
if ( !defined $key ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
48
|
1
|
|
|
|
|
4
|
$self->unlock; |
49
|
1
|
|
|
|
|
3
|
DBM::Deep->_throw_error( "Cannot use an undefined array index." ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
elsif ( $key =~ /^-?\d+$/ ) { |
52
|
231
|
100
|
|
|
|
628
|
if ( $key < 0 ) { |
53
|
11
|
|
|
|
|
35
|
$key += $self->FETCHSIZE; |
54
|
11
|
100
|
|
|
|
35
|
unless ( $key >= 0 ) { |
55
|
1
|
|
|
|
|
4
|
$self->unlock; |
56
|
1
|
|
|
|
|
4
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ( $key ne 'length' ) { |
61
|
1
|
|
|
|
|
5
|
$self->unlock; |
62
|
1
|
|
|
|
|
6
|
DBM::Deep->_throw_error( "Cannot use '$key' as an array index." ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
517
|
|
|
|
|
1542
|
my $rv = $self->SUPER::FETCH( $key ); |
66
|
|
|
|
|
|
|
|
67
|
517
|
|
|
|
|
1439
|
$self->unlock; |
68
|
|
|
|
|
|
|
|
69
|
517
|
|
|
|
|
2157
|
return $rv; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub STORE { |
73
|
303
|
|
|
303
|
|
1806
|
my $self = shift->_get_self; |
74
|
303
|
|
|
|
|
663
|
my ($key, $value) = @_; |
75
|
|
|
|
|
|
|
|
76
|
303
|
|
|
|
|
822
|
$self->lock_exclusive; |
77
|
|
|
|
|
|
|
|
78
|
303
|
|
|
|
|
555
|
my $size; |
79
|
|
|
|
|
|
|
my $idx_is_numeric; |
80
|
303
|
100
|
|
|
|
2144
|
if ( !defined $key ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
81
|
1
|
|
|
|
|
5
|
$self->unlock; |
82
|
1
|
|
|
|
|
3
|
DBM::Deep->_throw_error( "Cannot use an undefined array index." ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
elsif ( $key =~ /^-?\d+$/ ) { |
85
|
151
|
|
|
|
|
288
|
$idx_is_numeric = 1; |
86
|
151
|
100
|
|
|
|
369
|
if ( $key < 0 ) { |
87
|
2
|
|
|
|
|
7
|
$size = $self->FETCHSIZE; |
88
|
2
|
100
|
|
|
|
85
|
if ( $key + $size < 0 ) { |
89
|
1
|
|
|
|
|
14
|
die( "Modification of non-creatable array value attempted, subscript $key" ); |
90
|
|
|
|
|
|
|
} |
91
|
1
|
|
|
|
|
3
|
$key += $size |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ( $key ne 'length' ) { |
95
|
1
|
|
|
|
|
6
|
$self->unlock; |
96
|
1
|
|
|
|
|
6
|
DBM::Deep->_throw_error( "Cannot use '$key' as an array index." ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
300
|
|
|
|
|
959
|
my $rv = $self->SUPER::STORE( $key, $value ); |
100
|
|
|
|
|
|
|
|
101
|
300
|
100
|
|
|
|
685
|
if ( $idx_is_numeric ) { |
102
|
150
|
100
|
|
|
|
473
|
$size = $self->FETCHSIZE unless defined $size; |
103
|
150
|
100
|
|
|
|
421
|
if ( $key >= $size ) { |
104
|
129
|
|
|
|
|
335
|
$self->STORESIZE( $key + 1 ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
300
|
|
|
|
|
746
|
$self->unlock; |
109
|
|
|
|
|
|
|
|
110
|
300
|
|
|
|
|
864
|
return $rv; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub EXISTS { |
114
|
9
|
|
|
9
|
|
1847
|
my $self = shift->_get_self; |
115
|
9
|
|
|
|
|
24
|
my ($key) = @_; |
116
|
|
|
|
|
|
|
|
117
|
9
|
|
|
|
|
35
|
$self->lock_shared; |
118
|
|
|
|
|
|
|
|
119
|
9
|
100
|
|
|
|
75
|
if ( !defined $key ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
120
|
1
|
|
|
|
|
5
|
$self->unlock; |
121
|
1
|
|
|
|
|
5
|
DBM::Deep->_throw_error( "Cannot use an undefined array index." ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
elsif ( $key =~ /^-?\d+$/ ) { |
124
|
7
|
100
|
|
|
|
26
|
if ( $key < 0 ) { |
125
|
2
|
|
|
|
|
6
|
$key += $self->FETCHSIZE; |
126
|
2
|
100
|
|
|
|
7
|
unless ( $key >= 0 ) { |
127
|
1
|
|
|
|
|
4
|
$self->unlock; |
128
|
1
|
|
|
|
|
5
|
return; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
elsif ( $key ne 'length' ) { |
133
|
1
|
|
|
|
|
5
|
$self->unlock; |
134
|
1
|
|
|
|
|
7
|
DBM::Deep->_throw_error( "Cannot use '$key' as an array index." ); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
6
|
|
|
|
|
30
|
my $rv = $self->SUPER::EXISTS( $key ); |
138
|
|
|
|
|
|
|
|
139
|
6
|
|
|
|
|
21
|
$self->unlock; |
140
|
|
|
|
|
|
|
|
141
|
6
|
|
|
|
|
43
|
return $rv; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub DELETE { |
145
|
20
|
|
|
20
|
|
47
|
my $self = shift->_get_self; |
146
|
20
|
|
|
|
|
46
|
my ($key) = @_; |
147
|
20
|
|
|
|
|
27
|
warn "ARRAY::DELETE($self,$key)\n" if DBM::Deep::DEBUG; |
148
|
|
|
|
|
|
|
|
149
|
20
|
|
|
|
|
65
|
$self->lock_exclusive; |
150
|
|
|
|
|
|
|
|
151
|
20
|
|
|
|
|
52
|
my $size = $self->FETCHSIZE; |
152
|
20
|
100
|
|
|
|
142
|
if ( !defined $key ) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
153
|
1
|
|
|
|
|
5
|
$self->unlock; |
154
|
1
|
|
|
|
|
4
|
DBM::Deep->_throw_error( "Cannot use an undefined array index." ); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
elsif ( $key =~ /^-?\d+$/ ) { |
157
|
18
|
100
|
|
|
|
49
|
if ( $key < 0 ) { |
158
|
3
|
|
|
|
|
13
|
$key += $size; |
159
|
3
|
100
|
|
|
|
11
|
unless ( $key >= 0 ) { |
160
|
2
|
|
|
|
|
6
|
$self->unlock; |
161
|
2
|
|
|
|
|
13
|
return; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
elsif ( $key ne 'length' ) { |
166
|
1
|
|
|
|
|
6
|
$self->unlock; |
167
|
1
|
|
|
|
|
6
|
DBM::Deep->_throw_error( "Cannot use '$key' as an array index." ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
16
|
|
|
|
|
45
|
my $rv = $self->SUPER::DELETE( $key ); |
171
|
|
|
|
|
|
|
|
172
|
16
|
100
|
100
|
|
|
81
|
if ($rv && $key == $size - 1) { |
173
|
10
|
|
|
|
|
31
|
$self->STORESIZE( $key ); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
16
|
|
|
|
|
42
|
$self->unlock; |
177
|
|
|
|
|
|
|
|
178
|
16
|
|
|
|
|
40
|
return $rv; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# Now that we have a real Reference sector, we should store arrayzize there. |
182
|
|
|
|
|
|
|
# However, arraysize needs to be transactionally-aware, so a simple location to |
183
|
|
|
|
|
|
|
# store it isn't going to work. |
184
|
|
|
|
|
|
|
sub FETCHSIZE { |
185
|
287
|
|
|
287
|
|
13016
|
my $self = shift->_get_self; |
186
|
|
|
|
|
|
|
|
187
|
287
|
|
|
|
|
918
|
$self->lock_shared; |
188
|
|
|
|
|
|
|
|
189
|
287
|
|
|
|
|
704
|
my $SAVE_FILTER = $self->_engine->storage->{filter_fetch_value}; |
190
|
287
|
|
|
|
|
659
|
$self->_engine->storage->{filter_fetch_value} = undef; |
191
|
|
|
|
|
|
|
|
192
|
287
|
|
100
|
|
|
653
|
my $size = $self->FETCH('length') || 0; |
193
|
|
|
|
|
|
|
|
194
|
287
|
|
|
|
|
688
|
$self->_engine->storage->{filter_fetch_value} = $SAVE_FILTER; |
195
|
|
|
|
|
|
|
|
196
|
287
|
|
|
|
|
772
|
$self->unlock; |
197
|
|
|
|
|
|
|
|
198
|
287
|
|
|
|
|
896
|
return $size; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub STORESIZE { |
202
|
150
|
|
|
150
|
|
335
|
my $self = shift->_get_self; |
203
|
150
|
|
|
|
|
282
|
my ($new_length) = @_; |
204
|
|
|
|
|
|
|
|
205
|
150
|
|
|
|
|
456
|
$self->lock_exclusive; |
206
|
|
|
|
|
|
|
|
207
|
150
|
|
|
|
|
392
|
my $SAVE_FILTER = $self->_engine->storage->{filter_store_value}; |
208
|
150
|
|
|
|
|
349
|
$self->_engine->storage->{filter_store_value} = undef; |
209
|
|
|
|
|
|
|
|
210
|
150
|
|
|
|
|
490
|
my $result = $self->STORE('length', $new_length, 'length'); |
211
|
|
|
|
|
|
|
|
212
|
150
|
|
|
|
|
364
|
$self->_engine->storage->{filter_store_value} = $SAVE_FILTER; |
213
|
|
|
|
|
|
|
|
214
|
150
|
|
|
|
|
391
|
$self->unlock; |
215
|
|
|
|
|
|
|
|
216
|
150
|
|
|
|
|
275
|
return $result; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub POP { |
220
|
2
|
|
|
2
|
|
6
|
my $self = shift->_get_self; |
221
|
|
|
|
|
|
|
|
222
|
2
|
|
|
|
|
8
|
$self->lock_exclusive; |
223
|
|
|
|
|
|
|
|
224
|
2
|
|
|
|
|
6
|
my $length = $self->FETCHSIZE(); |
225
|
|
|
|
|
|
|
|
226
|
2
|
100
|
|
|
|
7
|
if ($length) { |
227
|
1
|
|
|
|
|
4
|
my $content = $self->FETCH( $length - 1 ); |
228
|
1
|
|
|
|
|
6
|
$self->DELETE( $length - 1 ); |
229
|
|
|
|
|
|
|
|
230
|
1
|
|
|
|
|
4
|
$self->unlock; |
231
|
|
|
|
|
|
|
|
232
|
1
|
|
|
|
|
3
|
return $content; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
else { |
235
|
1
|
|
|
|
|
3
|
$self->unlock; |
236
|
1
|
|
|
|
|
6
|
return; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub PUSH { |
241
|
8
|
|
|
8
|
|
31
|
my $self = shift->_get_self; |
242
|
|
|
|
|
|
|
|
243
|
8
|
|
|
|
|
29
|
$self->lock_exclusive; |
244
|
|
|
|
|
|
|
|
245
|
8
|
|
|
|
|
28
|
my $length = $self->FETCHSIZE(); |
246
|
|
|
|
|
|
|
|
247
|
8
|
|
|
|
|
49
|
for my $content (@_) { |
248
|
20
|
|
|
|
|
57
|
$self->STORE( $length, $content ); |
249
|
20
|
|
|
|
|
48
|
$length++; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
8
|
|
|
|
|
21
|
$self->unlock; |
253
|
|
|
|
|
|
|
|
254
|
8
|
|
|
|
|
42
|
return $length; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# XXX This really needs to be something more direct within the file, not a |
258
|
|
|
|
|
|
|
# fetch and re-store. -RobK, 2007-09-20 |
259
|
|
|
|
|
|
|
sub _move_value { |
260
|
29
|
|
|
29
|
|
51
|
my $self = shift; |
261
|
29
|
|
|
|
|
62
|
my ($old_key, $new_key) = @_; |
262
|
|
|
|
|
|
|
|
263
|
29
|
|
|
|
|
102
|
return $self->_engine->make_reference( $self, $old_key, $new_key ); |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
sub SHIFT { |
267
|
3
|
|
|
3
|
|
47
|
my $self = shift->_get_self; |
268
|
3
|
|
|
|
|
6
|
warn "SHIFT($self)\n" if DBM::Deep::DEBUG; |
269
|
|
|
|
|
|
|
|
270
|
3
|
|
|
|
|
10
|
$self->lock_exclusive; |
271
|
|
|
|
|
|
|
|
272
|
3
|
|
|
|
|
8
|
my $length = $self->FETCHSIZE(); |
273
|
|
|
|
|
|
|
|
274
|
3
|
100
|
|
|
|
12
|
if ( !$length ) { |
275
|
1
|
|
|
|
|
4
|
$self->unlock; |
276
|
1
|
|
|
|
|
5
|
return; |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
2
|
|
|
|
|
7
|
my $content = $self->DELETE( 0 ); |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
# Unless the deletion above has cleared the array ... |
282
|
2
|
50
|
|
|
|
8
|
if ( $length > 1 ) { |
283
|
2
|
|
|
|
|
9
|
for (my $i = 0; $i < $length - 1; $i++) { |
284
|
4
|
|
|
|
|
13
|
$self->_move_value( $i+1, $i ); |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
2
|
|
|
|
|
8
|
$self->DELETE( $length - 1 ); |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
2
|
|
|
|
|
10
|
$self->unlock; |
291
|
|
|
|
|
|
|
|
292
|
2
|
|
|
|
|
12
|
return $content; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
sub UNSHIFT { |
296
|
7
|
|
|
7
|
|
73
|
my $self = shift->_get_self; |
297
|
7
|
|
|
|
|
21
|
my @new_elements = @_; |
298
|
|
|
|
|
|
|
|
299
|
7
|
|
|
|
|
25
|
$self->lock_exclusive; |
300
|
|
|
|
|
|
|
|
301
|
7
|
|
|
|
|
20
|
my $length = $self->FETCHSIZE(); |
302
|
7
|
|
|
|
|
21
|
my $new_size = scalar @new_elements; |
303
|
|
|
|
|
|
|
|
304
|
7
|
100
|
|
|
|
24
|
if ($length) { |
305
|
6
|
|
|
|
|
24
|
for (my $i = $length - 1; $i >= 0; $i--) { |
306
|
18
|
|
|
|
|
55
|
$self->_move_value( $i, $i+$new_size ); |
307
|
|
|
|
|
|
|
} |
308
|
|
|
|
|
|
|
|
309
|
6
|
|
|
|
|
25
|
$self->STORESIZE( $length + $new_size ); |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
|
312
|
7
|
|
|
|
|
27
|
for (my $i = 0; $i < $new_size; $i++) { |
313
|
11
|
|
|
|
|
35
|
$self->STORE( $i, $new_elements[$i] ); |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
7
|
|
|
|
|
25
|
$self->unlock; |
317
|
|
|
|
|
|
|
|
318
|
7
|
|
|
|
|
50
|
return $length + $new_size; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
sub SPLICE { |
322
|
7
|
|
|
7
|
|
84
|
my $self = shift->_get_self; |
323
|
|
|
|
|
|
|
|
324
|
7
|
|
|
|
|
26
|
$self->lock_exclusive; |
325
|
|
|
|
|
|
|
|
326
|
7
|
|
|
|
|
23
|
my $length = $self->FETCHSIZE(); |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
## |
329
|
|
|
|
|
|
|
# Calculate offset and length of splice |
330
|
|
|
|
|
|
|
## |
331
|
7
|
|
|
|
|
16
|
my $offset = shift; |
332
|
7
|
100
|
|
|
|
19
|
$offset = 0 unless defined $offset; |
333
|
7
|
100
|
|
|
|
21
|
if ($offset < 0) { $offset += $length; } |
|
1
|
|
|
|
|
3
|
|
334
|
|
|
|
|
|
|
|
335
|
7
|
|
|
|
|
10
|
my $splice_length; |
336
|
7
|
100
|
|
|
|
21
|
if (scalar @_) { $splice_length = shift; } |
|
5
|
|
|
|
|
10
|
|
337
|
2
|
|
|
|
|
5
|
else { $splice_length = $length - $offset; } |
338
|
7
|
100
|
|
|
|
19
|
if ($splice_length < 0) { $splice_length += ($length - $offset); } |
|
1
|
|
|
|
|
4
|
|
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
## |
341
|
|
|
|
|
|
|
# Setup array with new elements, and copy out old elements for return |
342
|
|
|
|
|
|
|
## |
343
|
7
|
|
|
|
|
24
|
my @new_elements = @_; |
344
|
7
|
|
|
|
|
13
|
my $new_size = scalar @new_elements; |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
my @old_elements = map { |
347
|
7
|
|
|
|
|
24
|
$self->FETCH( $_ ) |
|
9
|
|
|
|
|
21
|
|
348
|
|
|
|
|
|
|
} $offset .. ($offset + $splice_length - 1); |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
## |
351
|
|
|
|
|
|
|
# Adjust array length, and shift elements to accommodate new section. |
352
|
|
|
|
|
|
|
## |
353
|
7
|
50
|
|
|
|
25
|
if ( $new_size != $splice_length ) { |
354
|
7
|
100
|
|
|
|
20
|
if ($new_size > $splice_length) { |
355
|
3
|
|
|
|
|
14
|
for (my $i = $length - 1; $i >= $offset + $splice_length; $i--) { |
356
|
5
|
|
|
|
|
20
|
$self->_move_value( $i, $i + ($new_size - $splice_length) ); |
357
|
|
|
|
|
|
|
} |
358
|
3
|
|
|
|
|
14
|
$self->STORESIZE( $length + $new_size - $splice_length ); |
359
|
|
|
|
|
|
|
} |
360
|
|
|
|
|
|
|
else { |
361
|
4
|
|
|
|
|
16
|
for (my $i = $offset + $splice_length; $i < $length; $i++) { |
362
|
2
|
|
|
|
|
21
|
$self->_move_value( $i, $i + ($new_size - $splice_length) ); |
363
|
|
|
|
|
|
|
} |
364
|
4
|
|
|
|
|
13
|
for (my $i = 0; $i < $splice_length - $new_size; $i++) { |
365
|
7
|
|
|
|
|
25
|
$self->DELETE( $length - 1 ); |
366
|
7
|
|
|
|
|
58
|
$length--; |
367
|
|
|
|
|
|
|
} |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
## |
372
|
|
|
|
|
|
|
# Insert new elements into array |
373
|
|
|
|
|
|
|
## |
374
|
7
|
|
|
|
|
26
|
for (my $i = $offset; $i < $offset + $new_size; $i++) { |
375
|
7
|
|
|
|
|
20
|
$self->STORE( $i, shift @new_elements ); |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
|
378
|
7
|
|
|
|
|
21
|
$self->unlock; |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
## |
381
|
|
|
|
|
|
|
# Return deleted section, or last element in scalar context. |
382
|
|
|
|
|
|
|
## |
383
|
7
|
100
|
|
|
|
48
|
return wantarray ? @old_elements : $old_elements[-1]; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
# We don't need to populate it, yet. |
387
|
|
|
|
|
|
|
# It will be useful, though, when we split out HASH and ARRAY |
388
|
|
|
|
|
|
|
# Perl will call EXTEND() when the array is likely to grow. |
389
|
|
|
|
|
|
|
# We don't care, but include it because it gets called at times. |
390
|
|
|
|
21
|
|
|
sub EXTEND {} |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
sub _copy_node { |
393
|
23
|
|
|
23
|
|
45
|
my $self = shift; |
394
|
23
|
|
|
|
|
42
|
my ($db_temp) = @_; |
395
|
|
|
|
|
|
|
|
396
|
23
|
|
|
|
|
69
|
my $length = $self->length(); |
397
|
23
|
|
|
|
|
77
|
for (my $index = 0; $index < $length; $index++) { |
398
|
30
|
|
|
|
|
122
|
$self->_copy_value( \$db_temp->[$index], $self->get($index) ); |
399
|
|
|
|
|
|
|
} |
400
|
|
|
|
|
|
|
|
401
|
23
|
|
|
|
|
52
|
return 1; |
402
|
|
|
|
|
|
|
} |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
sub _clear { |
405
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
406
|
|
|
|
|
|
|
|
407
|
1
|
|
|
|
|
5
|
my $size = $self->FETCHSIZE; |
408
|
1
|
|
|
|
|
5
|
for my $key ( 0 .. $size - 1 ) { |
409
|
5
|
|
|
|
|
15
|
$self->_engine->delete_key( $self, $key, $key ); |
410
|
|
|
|
|
|
|
} |
411
|
1
|
|
|
|
|
7
|
$self->STORESIZE( 0 ); |
412
|
|
|
|
|
|
|
|
413
|
1
|
|
|
|
|
3
|
return; |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
|
416
|
46
|
|
|
46
|
1
|
2989
|
sub length { (shift)->FETCHSIZE(@_) } |
417
|
2
|
|
|
2
|
1
|
9
|
sub pop { (shift)->POP(@_) } |
418
|
5
|
|
|
5
|
1
|
23
|
sub push { (shift)->PUSH(@_) } |
419
|
3
|
|
|
3
|
1
|
24
|
sub unshift { (shift)->UNSHIFT(@_) } |
420
|
6
|
|
|
6
|
1
|
26
|
sub splice { (shift)->SPLICE(@_) } |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
# This must be last otherwise we have to qualify all other calls to shift |
423
|
|
|
|
|
|
|
# as calls to CORE::shift |
424
|
2
|
|
|
2
|
1
|
10
|
sub shift { (CORE::shift)->SHIFT(@_) } |
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
1; |
427
|
|
|
|
|
|
|
__END__ |