Filename | /usr/lib/perl/5.10/Hash/Util.pm |
Statements | Executed 669 statements in 2.60ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
17 | 1 | 1 | 1.13ms | 1.18ms | lock_ref_keys | Hash::Util::
17 | 1 | 1 | 93µs | 1.28ms | lock_keys | Hash::Util::
1 | 1 | 1 | 35µs | 35µs | bootstrap (xsub) | Hash::Util::
1 | 1 | 1 | 28µs | 35µs | BEGIN@4 | Hash::Util::
1 | 1 | 1 | 13µs | 36µs | BEGIN@6 | Hash::Util::
1 | 1 | 1 | 12µs | 89µs | BEGIN@5 | Hash::Util::
1 | 1 | 1 | 11µs | 48µs | BEGIN@8 | Hash::Util::
1 | 1 | 1 | 11µs | 98µs | BEGIN@7 | Hash::Util::
0 | 0 | 0 | 0s | 0s | hash_seed | Hash::Util::
0 | 0 | 0 | 0s | 0s | hash_unlocked | Hash::Util::
0 | 0 | 0 | 0s | 0s | hashref_unlocked | Hash::Util::
0 | 0 | 0 | 0s | 0s | hidden_keys | Hash::Util::
0 | 0 | 0 | 0s | 0s | import | Hash::Util::
0 | 0 | 0 | 0s | 0s | legal_keys | Hash::Util::
0 | 0 | 0 | 0s | 0s | lock_hash | Hash::Util::
0 | 0 | 0 | 0s | 0s | lock_hash_recurse | Hash::Util::
0 | 0 | 0 | 0s | 0s | lock_hashref | Hash::Util::
0 | 0 | 0 | 0s | 0s | lock_hashref_recurse | Hash::Util::
0 | 0 | 0 | 0s | 0s | lock_keys_plus | Hash::Util::
0 | 0 | 0 | 0s | 0s | lock_ref_keys_plus | Hash::Util::
0 | 0 | 0 | 0s | 0s | lock_ref_value | Hash::Util::
0 | 0 | 0 | 0s | 0s | lock_value | Hash::Util::
0 | 0 | 0 | 0s | 0s | unlock_hash | Hash::Util::
0 | 0 | 0 | 0s | 0s | unlock_hash_recurse | Hash::Util::
0 | 0 | 0 | 0s | 0s | unlock_hashref | Hash::Util::
0 | 0 | 0 | 0s | 0s | unlock_hashref_recurse | Hash::Util::
0 | 0 | 0 | 0s | 0s | unlock_keys | Hash::Util::
0 | 0 | 0 | 0s | 0s | unlock_ref_keys | Hash::Util::
0 | 0 | 0 | 0s | 0s | unlock_ref_value | Hash::Util::
0 | 0 | 0 | 0s | 0s | unlock_value | Hash::Util::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Hash::Util; | ||||
2 | |||||
3 | 1 | 39µs | require 5.007003; | ||
4 | 3 | 36µs | 2 | 42µs | # spent 35µs (28+7) within Hash::Util::BEGIN@4 which was called:
# once (28µs+7µs) by fields::__ANON__[/usr/share/perl/5.10/fields.pm:128] at line 4 # spent 35µs making 1 call to Hash::Util::BEGIN@4
# spent 7µs making 1 call to strict::import |
5 | 3 | 34µs | 2 | 167µs | # spent 89µs (12+77) within Hash::Util::BEGIN@5 which was called:
# once (12µs+77µs) by fields::__ANON__[/usr/share/perl/5.10/fields.pm:128] at line 5 # spent 89µs making 1 call to Hash::Util::BEGIN@5
# spent 77µs making 1 call to Exporter::import |
6 | 3 | 29µs | 2 | 59µs | # spent 36µs (13+23) within Hash::Util::BEGIN@6 which was called:
# once (13µs+23µs) by fields::__ANON__[/usr/share/perl/5.10/fields.pm:128] at line 6 # spent 36µs making 1 call to Hash::Util::BEGIN@6
# spent 23µs making 1 call to warnings::import |
7 | 3 | 34µs | 2 | 185µs | # spent 98µs (11+87) within Hash::Util::BEGIN@7 which was called:
# once (11µs+87µs) by fields::__ANON__[/usr/share/perl/5.10/fields.pm:128] at line 7 # spent 98µs making 1 call to Hash::Util::BEGIN@7
# spent 87µs making 1 call to warnings::register::import |
8 | 3 | 1.04ms | 2 | 86µs | # spent 48µs (11+37) within Hash::Util::BEGIN@8 which was called:
# once (11µs+37µs) by fields::__ANON__[/usr/share/perl/5.10/fields.pm:128] at line 8 # spent 48µs making 1 call to Hash::Util::BEGIN@8
# spent 38µs making 1 call to Exporter::import |
9 | |||||
10 | 1 | 1µs | require Exporter; | ||
11 | 1 | 17µs | our @ISA = qw(Exporter); | ||
12 | 1 | 6µs | our @EXPORT_OK = qw( | ||
13 | fieldhash fieldhashes | ||||
14 | |||||
15 | all_keys | ||||
16 | lock_keys unlock_keys | ||||
17 | lock_value unlock_value | ||||
18 | lock_hash unlock_hash | ||||
19 | lock_keys_plus hash_locked | ||||
20 | hidden_keys legal_keys | ||||
21 | |||||
22 | lock_ref_keys unlock_ref_keys | ||||
23 | lock_ref_value unlock_ref_value | ||||
24 | lock_hashref unlock_hashref | ||||
25 | lock_ref_keys_plus hashref_locked | ||||
26 | hidden_ref_keys legal_ref_keys | ||||
27 | |||||
28 | hash_seed hv_store | ||||
29 | |||||
30 | ); | ||||
31 | 1 | 400ns | our $VERSION = 0.07; | ||
32 | 1 | 900ns | require DynaLoader; | ||
33 | 1 | 13µs | local @ISA = qw(DynaLoader); | ||
34 | 1 | 9µs | 1 | 337µs | bootstrap Hash::Util $VERSION; # spent 337µs making 1 call to DynaLoader::bootstrap |
35 | |||||
36 | sub import { | ||||
37 | my $class = shift; | ||||
38 | if ( grep /fieldhash/, @_ ) { | ||||
39 | require Hash::Util::FieldHash; | ||||
40 | Hash::Util::FieldHash->import(':all'); # for re-export | ||||
41 | } | ||||
42 | unshift @_, $class; | ||||
43 | goto &Exporter::import; | ||||
44 | } | ||||
45 | |||||
46 | # spent 1.18ms (1.13+51µs) within Hash::Util::lock_ref_keys which was called 17 times, avg 70µs/call:
# 17 times (1.13ms+51µs) by Hash::Util::lock_keys at line 81, avg 70µs/call | ||||
47 | 17 | 57µs | my($hash, @keys) = @_; | ||
48 | |||||
49 | 17 | 85µs | 17 | 26µs | Internals::hv_clear_placeholders %$hash; # spent 26µs making 17 calls to Internals::hv_clear_placeholders, avg 2µs/call |
50 | 17 | 20µs | if( @keys ) { | ||
51 | 17 | 182µs | my %keys = map { ($_ => 1) } @keys; | ||
52 | 17 | 25µs | my %original_keys = map { ($_ => 1) } keys %$hash; | ||
53 | 17 | 40µs | foreach my $k (keys %original_keys) { | ||
54 | croak "Hash has key '$k' which is not in the new key set" | ||||
55 | unless $keys{$k}; | ||||
56 | } | ||||
57 | |||||
58 | 17 | 18µs | foreach my $k (@keys) { | ||
59 | 229 | 319µs | $hash->{$k} = undef unless exists $hash->{$k}; | ||
60 | } | ||||
61 | 17 | 101µs | 17 | 25µs | Internals::SvREADONLY %$hash, 1; # spent 25µs making 17 calls to Internals::SvREADONLY, avg 1µs/call |
62 | |||||
63 | 17 | 46µs | foreach my $k (@keys) { | ||
64 | 229 | 245µs | delete $hash->{$k} unless $original_keys{$k}; | ||
65 | } | ||||
66 | } | ||||
67 | else { | ||||
68 | Internals::SvREADONLY %$hash, 1; | ||||
69 | } | ||||
70 | |||||
71 | 17 | 77µs | return $hash; | ||
72 | } | ||||
73 | |||||
74 | sub unlock_ref_keys { | ||||
75 | my $hash = shift; | ||||
76 | |||||
77 | Internals::SvREADONLY %$hash, 0; | ||||
78 | return $hash; | ||||
79 | } | ||||
80 | |||||
81 | 17 | 82µs | 17 | 1.18ms | # spent 1.28ms (93µs+1.18) within Hash::Util::lock_keys which was called 17 times, avg 75µs/call:
# 17 times (93µs+1.18ms) by fields::__ANON__[/usr/share/perl/5.10/fields.pm:128] at line 126 of fields.pm, avg 75µs/call # spent 1.18ms making 17 calls to Hash::Util::lock_ref_keys, avg 70µs/call |
82 | sub unlock_keys (\%) { unlock_ref_keys(@_) } | ||||
83 | |||||
84 | sub lock_ref_keys_plus { | ||||
85 | my ($hash,@keys)=@_; | ||||
86 | my @delete; | ||||
87 | Internals::hv_clear_placeholders(%$hash); | ||||
88 | foreach my $key (@keys) { | ||||
89 | unless (exists($hash->{$key})) { | ||||
90 | $hash->{$key}=undef; | ||||
91 | push @delete,$key; | ||||
92 | } | ||||
93 | } | ||||
94 | Internals::SvREADONLY(%$hash,1); | ||||
95 | delete @{$hash}{@delete}; | ||||
96 | return $hash | ||||
97 | } | ||||
98 | |||||
99 | sub lock_keys_plus(\%;@) { lock_ref_keys_plus(@_) } | ||||
100 | |||||
101 | sub lock_ref_value { | ||||
102 | my($hash, $key) = @_; | ||||
103 | # I'm doubtful about this warning, as it seems not to be true. | ||||
104 | # Marking a value in the hash as RO is useful, regardless | ||||
105 | # of the status of the hash itself. | ||||
106 | carp "Cannot usefully lock values in an unlocked hash" | ||||
107 | if !Internals::SvREADONLY(%$hash) && warnings::enabled; | ||||
108 | Internals::SvREADONLY $hash->{$key}, 1; | ||||
109 | return $hash | ||||
110 | } | ||||
111 | |||||
112 | sub unlock_ref_value { | ||||
113 | my($hash, $key) = @_; | ||||
114 | Internals::SvREADONLY $hash->{$key}, 0; | ||||
115 | return $hash | ||||
116 | } | ||||
117 | |||||
118 | sub lock_value (\%$) { lock_ref_value(@_) } | ||||
119 | sub unlock_value (\%$) { unlock_ref_value(@_) } | ||||
120 | |||||
121 | sub lock_hashref { | ||||
122 | my $hash = shift; | ||||
123 | |||||
124 | lock_ref_keys($hash); | ||||
125 | |||||
126 | foreach my $value (values %$hash) { | ||||
127 | Internals::SvREADONLY($value,1); | ||||
128 | } | ||||
129 | |||||
130 | return $hash; | ||||
131 | } | ||||
132 | |||||
133 | sub unlock_hashref { | ||||
134 | my $hash = shift; | ||||
135 | |||||
136 | foreach my $value (values %$hash) { | ||||
137 | Internals::SvREADONLY($value, 0); | ||||
138 | } | ||||
139 | |||||
140 | unlock_ref_keys($hash); | ||||
141 | |||||
142 | return $hash; | ||||
143 | } | ||||
144 | |||||
145 | sub lock_hash (\%) { lock_hashref(@_) } | ||||
146 | sub unlock_hash (\%) { unlock_hashref(@_) } | ||||
147 | |||||
148 | sub lock_hashref_recurse { | ||||
149 | my $hash = shift; | ||||
150 | |||||
151 | lock_ref_keys($hash); | ||||
152 | foreach my $value (values %$hash) { | ||||
153 | if (reftype($value) eq 'HASH') { | ||||
154 | lock_hashref_recurse($value); | ||||
155 | } | ||||
156 | Internals::SvREADONLY($value,1); | ||||
157 | } | ||||
158 | return $hash | ||||
159 | } | ||||
160 | |||||
161 | sub unlock_hashref_recurse { | ||||
162 | my $hash = shift; | ||||
163 | |||||
164 | foreach my $value (values %$hash) { | ||||
165 | if (reftype($value) eq 'HASH') { | ||||
166 | unlock_hashref_recurse($value); | ||||
167 | } | ||||
168 | Internals::SvREADONLY($value,1); | ||||
169 | } | ||||
170 | unlock_ref_keys($hash); | ||||
171 | return $hash; | ||||
172 | } | ||||
173 | |||||
174 | sub lock_hash_recurse (\%) { lock_hashref_recurse(@_) } | ||||
175 | sub unlock_hash_recurse (\%) { unlock_hashref_recurse(@_) } | ||||
176 | |||||
177 | sub hashref_unlocked { | ||||
178 | my $hash=shift; | ||||
179 | return Internals::SvREADONLY($hash) | ||||
180 | } | ||||
181 | |||||
182 | sub hash_unlocked(\%) { hashref_unlocked(@_) } | ||||
183 | |||||
184 | sub legal_keys(\%) { legal_ref_keys(@_) } | ||||
185 | sub hidden_keys(\%){ hidden_ref_keys(@_) } | ||||
186 | |||||
187 | sub hash_seed () { | ||||
188 | Internals::rehash_seed(); | ||||
189 | } | ||||
190 | |||||
191 | 1 | 47µs | 1; | ||
# spent 35µs within Hash::Util::bootstrap which was called:
# once (35µs+0s) by DynaLoader::bootstrap at line 215 of DynaLoader.pm |