line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::StoredIterator; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
2099760
|
use 5.010000; |
|
10
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
400
|
|
4
|
10
|
|
|
10
|
|
60
|
use strict; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
270
|
|
5
|
10
|
|
|
10
|
|
50
|
use warnings; |
|
10
|
|
|
|
|
80
|
|
|
10
|
|
|
|
|
280
|
|
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
50
|
use base 'Exporter'; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
3330
|
|
8
|
10
|
|
|
10
|
|
80
|
use Carp qw/croak carp/; |
|
10
|
|
|
|
|
10
|
|
|
10
|
|
|
|
|
2100
|
|
9
|
10
|
|
|
10
|
|
80
|
use B; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
10040
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw{ |
12
|
|
|
|
|
|
|
hmap |
13
|
|
|
|
|
|
|
eich |
14
|
|
|
|
|
|
|
eech |
15
|
|
|
|
|
|
|
iterator |
16
|
|
|
|
|
|
|
hash_get_iterator |
17
|
|
|
|
|
|
|
hash_set_iterator |
18
|
|
|
|
|
|
|
hash_init_iterator |
19
|
|
|
|
|
|
|
hkeys |
20
|
|
|
|
|
|
|
hvalues |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.007'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
require XSLoader; |
26
|
|
|
|
|
|
|
XSLoader::load( 'Hash::StoredIterator', $VERSION ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub eich(\%\$) { |
29
|
33
|
|
|
33
|
1
|
13980563
|
carp "eich is deprecated, you should use iterator() instead"; |
30
|
33
|
|
|
|
|
2344555
|
my ( $hash, $i_ref ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
33
|
|
|
|
|
570
|
my $old_it = hash_get_iterator($hash); |
33
|
|
|
|
|
|
|
|
34
|
33
|
|
|
|
|
527
|
my ( $key, $val ); |
35
|
|
|
|
|
|
|
|
36
|
33
|
|
|
|
|
118
|
my $success = eval { |
37
|
33
|
100
|
|
|
|
172
|
if ( !defined $$i_ref ) |
38
|
|
|
|
|
|
|
{ |
39
|
9
|
|
|
|
|
67
|
hash_init_iterator($hash); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
24
|
|
|
|
|
131
|
hash_set_iterator( $hash, $$i_ref ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
33
|
|
|
|
|
131
|
( $key, $val ) = each(%$hash); |
46
|
|
|
|
|
|
|
|
47
|
33
|
|
|
|
|
84
|
$$i_ref = hash_get_iterator($hash); |
48
|
|
|
|
|
|
|
|
49
|
33
|
|
|
|
|
63
|
1; |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
33
|
|
|
|
|
114
|
hash_set_iterator( $hash, $old_it ); |
53
|
33
|
50
|
|
|
|
129
|
die $@ unless $success; |
54
|
|
|
|
|
|
|
|
55
|
33
|
100
|
|
|
|
123
|
unless ( defined $key ) { |
56
|
8
|
|
|
|
|
11
|
$$i_ref = undef; |
57
|
8
|
|
|
|
|
59
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
25
|
|
|
|
|
91
|
return ( $key, $val ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub iterator(\%) { |
64
|
10
|
|
|
10
|
1
|
15296173
|
my ($hash) = @_; |
65
|
10
|
|
|
|
|
89
|
my $i = undef; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return sub { |
68
|
42
|
|
|
42
|
|
43694
|
my $old_it = hash_get_iterator($hash); |
69
|
|
|
|
|
|
|
|
70
|
42
|
|
|
|
|
87
|
my ( $key, $val ); |
71
|
|
|
|
|
|
|
|
72
|
42
|
|
|
|
|
58
|
my $success = eval { |
73
|
42
|
100
|
|
|
|
204
|
if ( !defined $i ) { |
74
|
11
|
|
|
|
|
65
|
hash_init_iterator( $hash ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
31
|
|
|
|
|
100
|
hash_set_iterator( $hash, $i ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
42
|
|
|
|
|
222
|
( $key, $val ) = each( %$hash ); |
81
|
|
|
|
|
|
|
|
82
|
42
|
|
|
|
|
152
|
$i = hash_get_iterator($hash); |
83
|
|
|
|
|
|
|
|
84
|
42
|
|
|
|
|
118
|
1; |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
|
87
|
42
|
|
|
|
|
138
|
hash_set_iterator( $hash, $old_it ); |
88
|
42
|
50
|
|
|
|
131
|
die $@ unless $success; |
89
|
|
|
|
|
|
|
|
90
|
42
|
100
|
|
|
|
139
|
unless ( defined $key ) { |
91
|
9
|
|
|
|
|
14
|
$i = undef; |
92
|
9
|
|
|
|
|
28
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
33
|
|
|
|
|
197
|
return ( $key, $val ); |
96
|
10
|
|
|
|
|
232
|
}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub hmap(&\%) { |
100
|
9
|
|
|
9
|
1
|
36433228
|
my ( $code, $hash ) = @_; |
101
|
|
|
|
|
|
|
|
102
|
9
|
|
|
|
|
212
|
my $old_it = hash_get_iterator($hash); |
103
|
9
|
|
|
|
|
119
|
hash_init_iterator($hash); |
104
|
|
|
|
|
|
|
|
105
|
9
|
|
|
|
|
48
|
my $success = eval { |
106
|
9
|
|
|
|
|
113
|
my $iter = iterator %$hash; |
107
|
|
|
|
|
|
|
|
108
|
9
|
|
|
|
|
61
|
while ( my ( $k, $v ) = $iter->() ) { |
109
|
29
|
|
|
|
|
41
|
local $_ = $k; |
110
|
|
|
|
|
|
|
# Can't use caller(), subref might be from a different package than |
111
|
|
|
|
|
|
|
# eech is called from. |
112
|
29
|
|
|
|
|
476
|
my $callback_package = B::svref_2object($code)->GV->STASH->NAME; |
113
|
10
|
|
|
10
|
|
110
|
no strict 'refs'; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
4020
|
|
114
|
29
|
|
|
|
|
72
|
local ${"$callback_package\::a"} = $k; |
|
29
|
|
|
|
|
213
|
|
115
|
29
|
|
|
|
|
43
|
local ${"$callback_package\::b"} = $v; |
|
29
|
|
|
|
|
135
|
|
116
|
29
|
|
|
|
|
89
|
$code->( $k, $v ); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
8
|
|
|
|
|
47
|
1; |
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
|
122
|
9
|
|
|
|
|
77
|
hash_set_iterator( $hash, $old_it ); |
123
|
9
|
100
|
|
|
|
52
|
die $@ unless $success; |
124
|
8
|
|
|
|
|
21
|
return; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub eech(&\%) { |
128
|
0
|
|
|
0
|
1
|
0
|
carp "eech is deprecated, use hmap instead"; |
129
|
0
|
|
|
|
|
0
|
goto &hmap; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub hkeys(\%) { |
133
|
19
|
|
|
19
|
1
|
24149214
|
my ($hash) = @_; |
134
|
19
|
50
|
|
|
|
95
|
croak "ARGH!" unless $hash; |
135
|
|
|
|
|
|
|
|
136
|
19
|
|
|
|
|
111
|
my $old_it = hash_get_iterator($hash); |
137
|
19
|
|
|
|
|
74
|
hash_init_iterator($hash); |
138
|
|
|
|
|
|
|
|
139
|
19
|
|
|
|
|
50
|
my @out = keys %$hash; |
140
|
|
|
|
|
|
|
|
141
|
19
|
|
|
|
|
59
|
hash_set_iterator( $hash, $old_it ); |
142
|
|
|
|
|
|
|
|
143
|
19
|
|
|
|
|
166
|
return @out; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub hvalues(\%) { |
147
|
1
|
|
|
1
|
1
|
7
|
my ($hash) = @_; |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
|
|
11
|
my $old_it = hash_get_iterator($hash); |
150
|
1
|
|
|
|
|
11
|
hash_init_iterator($hash); |
151
|
|
|
|
|
|
|
|
152
|
1
|
|
|
|
|
3
|
my @out = values %$hash; |
153
|
|
|
|
|
|
|
|
154
|
1
|
|
|
|
|
22
|
hash_set_iterator( $hash, $old_it ); |
155
|
|
|
|
|
|
|
|
156
|
1
|
|
|
|
|
24
|
return @out; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
__END__ |