| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tie::Array::Packed; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
47088
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
44
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
275
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require XSLoader; |
|
10
|
|
|
|
|
|
|
XSLoader::load('Tie::Array::Packed', $VERSION); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my @short = qw(c C F f d i I j J s! S! l! L! n N v V q Q e E); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %map = ( Char => 'c', |
|
15
|
|
|
|
|
|
|
UnsignedChar => 'C', |
|
16
|
|
|
|
|
|
|
Hex => 'h', |
|
17
|
|
|
|
|
|
|
NV => 'F', |
|
18
|
|
|
|
|
|
|
Number => 'F', |
|
19
|
|
|
|
|
|
|
FloatNative => 'f', |
|
20
|
|
|
|
|
|
|
DoubleNative => 'd', |
|
21
|
|
|
|
|
|
|
Integer => 'j', |
|
22
|
|
|
|
|
|
|
UnsignedInteger => 'J', |
|
23
|
|
|
|
|
|
|
IntegerPerl => 'j', |
|
24
|
|
|
|
|
|
|
IV => 'j', |
|
25
|
|
|
|
|
|
|
UnsignedIntegerPerl => 'J', |
|
26
|
|
|
|
|
|
|
UV => 'J', |
|
27
|
|
|
|
|
|
|
IntegerNative => 'i', |
|
28
|
|
|
|
|
|
|
UnsignedIntegerNative => 'I', |
|
29
|
|
|
|
|
|
|
ShortNative => 's!', |
|
30
|
|
|
|
|
|
|
UnsignedShortNative => 'S!', |
|
31
|
|
|
|
|
|
|
LongNative => 'l!', |
|
32
|
|
|
|
|
|
|
UnsignedLongNative => 'L!', |
|
33
|
|
|
|
|
|
|
UnsignedShortNet => 'n', |
|
34
|
|
|
|
|
|
|
UnsignedShortBE => 'n', |
|
35
|
|
|
|
|
|
|
UnsignedLongNet => 'N', |
|
36
|
|
|
|
|
|
|
UnsignedLongBE => 'N', |
|
37
|
|
|
|
|
|
|
UnsignedShortVax => 'v', |
|
38
|
|
|
|
|
|
|
UnsignedShortLE => 'v', |
|
39
|
|
|
|
|
|
|
UnsignedLongVax => 'V', |
|
40
|
|
|
|
|
|
|
UnsignedLongLE => 'V', |
|
41
|
|
|
|
|
|
|
Quad => 'q', |
|
42
|
|
|
|
|
|
|
UnsignedQuad => 'Q', |
|
43
|
|
|
|
|
|
|
LongLong => 'q', |
|
44
|
|
|
|
|
|
|
UnsignedLongLong => 'Q', |
|
45
|
|
|
|
|
|
|
Int64 => 'q', |
|
46
|
|
|
|
|
|
|
UInt64 => 'Q', |
|
47
|
|
|
|
|
|
|
Int128 => 'e', |
|
48
|
|
|
|
|
|
|
UInt128 => 'E', |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
@map{@short} = @short; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
for my $name (keys %map) { |
|
55
|
|
|
|
|
|
|
my $type = $map{$name}; |
|
56
|
|
|
|
|
|
|
|
|
57
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
960
|
|
|
58
|
|
|
|
|
|
|
@{"Tie::Array::Packed::${name}::ISA"} = __PACKAGE__; |
|
59
|
|
|
|
|
|
|
*{"Tie::Array::Packed::${name}::TIEARRAY"} = |
|
60
|
|
|
|
|
|
|
sub { |
|
61
|
21
|
|
|
21
|
|
4469
|
my $class = shift; |
|
62
|
21
|
|
|
|
|
28
|
my $self; |
|
63
|
21
|
50
|
|
|
|
305
|
$self = TIEARRAY($class, $type, defined $_[0] ? $_[0] : ''); |
|
64
|
21
|
50
|
|
|
|
82
|
if (@_ > 1) { |
|
65
|
21
|
|
|
|
|
29
|
shift; |
|
66
|
21
|
|
|
|
|
238
|
$self->SPLICE(0, scalar(@_), @_); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
21
|
|
|
|
|
70
|
$self; |
|
69
|
|
|
|
|
|
|
}; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub make { |
|
73
|
19
|
|
|
19
|
1
|
115416
|
my $class = shift; |
|
74
|
19
|
|
|
|
|
119
|
tie my(@self), $class, '', @_; |
|
75
|
|
|
|
|
|
|
return \@self |
|
76
|
19
|
|
|
|
|
58
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub make_with_packed { |
|
79
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
|
80
|
0
|
|
|
|
|
0
|
tie my(@self), $class, @_; |
|
81
|
|
|
|
|
|
|
return \@self |
|
82
|
0
|
|
|
|
|
0
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub make_clone { |
|
85
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
86
|
0
|
|
|
|
|
0
|
tie my(@clone), ref($self), $$self; |
|
87
|
0
|
|
|
|
|
0
|
return \@clone; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub string { |
|
91
|
1
|
|
|
1
|
0
|
964
|
my $self = shift; |
|
92
|
1
|
|
|
|
|
12
|
$$self; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $sort_packed_loaded; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _load_sort_packed { |
|
98
|
0
|
|
|
0
|
|
|
eval { require Sort::Packed }; |
|
|
0
|
|
|
|
|
|
|
|
99
|
0
|
0
|
0
|
|
|
|
croak __PACKAGE__ ."::sort requires package Sort::Packed" |
|
100
|
|
|
|
|
|
|
if ($@ or !$Sort::Packed::VERSION); |
|
101
|
0
|
|
|
|
|
|
$sort_packed_loaded++ |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub sort { |
|
105
|
0
|
0
|
|
0
|
1
|
|
@_ > 2 and croak 'Usage: tied(@parray)->sort([sub { CMP($a, $b) }])'; |
|
106
|
0
|
0
|
|
|
|
|
$sort_packed_loaded or _load_sort_packed; |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my $self = shift; |
|
109
|
0
|
|
|
|
|
|
my $packer = $self->packer; |
|
110
|
0
|
0
|
|
|
|
|
if (@_) { |
|
111
|
0
|
|
|
|
|
|
my $cmp = shift; |
|
112
|
0
|
|
|
|
|
|
&Sort::Packed::sort_packed_custom($cmp, $packer, $$self); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
else { |
|
115
|
0
|
|
|
|
|
|
&Sort::Packed::sort_packed($packer, $$self); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub shuffle { |
|
121
|
0
|
0
|
|
0
|
1
|
|
@_ != 1 and croak 'Usage: tied(@parray)->shuffle'; |
|
122
|
0
|
0
|
|
|
|
|
$sort_packed_loaded or _load_sort_packed; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $self = shift; |
|
125
|
0
|
|
|
|
|
|
Sort::Packed::shuffle_packed($self->packer, $$self) |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub grep { |
|
129
|
0
|
0
|
|
0
|
1
|
|
@_ != 2 and croak 'Usage: tied(@parray)->grep(sub { SELECT($_) })'; |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $self = shift; |
|
132
|
0
|
|
|
|
|
|
my $select = shift; |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $last = $self->FETCHSIZE - 1; |
|
135
|
0
|
|
|
|
|
|
my $slow = 0; |
|
136
|
0
|
|
|
|
|
|
for my $i (0..$last) { |
|
137
|
0
|
|
|
|
|
|
for ($self->FETCH($i)) { |
|
138
|
0
|
|
|
|
|
|
my $cp = $_; |
|
139
|
0
|
0
|
|
|
|
|
if (&$select) { |
|
140
|
0
|
0
|
|
|
|
|
$self->STORE($slow, $cp) if $slow < $i; |
|
141
|
0
|
|
|
|
|
|
$slow++ |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
} |
|
145
|
0
|
|
|
|
|
|
$self->STORESIZE($slow); |
|
146
|
0
|
|
|
|
|
|
$slow; |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
|
150
|
|
|
|
|
|
|
__END__ |