Filename | /usr/lib/x86_64-linux-gnu/perl-base/feature.pm |
Statements | Executed 155 statements in 138µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
3 | 1 | 1 | 91µs | 91µs | __common | feature::
3 | 3 | 3 | 9µs | 100µs | import | feature::
0 | 0 | 0 | 0s | 0s | croak | feature::
0 | 0 | 0 | 0s | 0s | feature_bundle | feature::
0 | 0 | 0 | 0s | 0s | feature_enabled | feature::
0 | 0 | 0 | 0s | 0s | features_enabled | feature::
0 | 0 | 0 | 0s | 0s | unimport | feature::
0 | 0 | 0 | 0s | 0s | unknown_feature | feature::
0 | 0 | 0 | 0s | 0s | unknown_feature_bundle | feature::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # -*- buffer-read-only: t -*- | ||||
2 | # !!!!!!! DO NOT EDIT THIS FILE !!!!!!! | ||||
3 | # This file is built by regen/feature.pl. | ||||
4 | # Any changes made here will be lost! | ||||
5 | |||||
6 | package feature; | ||||
7 | |||||
8 | 1 | 300ns | our $VERSION = '1.72'; | ||
9 | |||||
10 | 1 | 7µs | our %feature = ( | ||
11 | fc => 'feature_fc', | ||||
12 | isa => 'feature_isa', | ||||
13 | say => 'feature_say', | ||||
14 | try => 'feature_try', | ||||
15 | defer => 'feature_defer', | ||||
16 | state => 'feature_state', | ||||
17 | switch => 'feature_switch', | ||||
18 | bitwise => 'feature_bitwise', | ||||
19 | indirect => 'feature_indirect', | ||||
20 | evalbytes => 'feature_evalbytes', | ||||
21 | signatures => 'feature_signatures', | ||||
22 | current_sub => 'feature___SUB__', | ||||
23 | refaliasing => 'feature_refaliasing', | ||||
24 | postderef_qq => 'feature_postderef_qq', | ||||
25 | unicode_eval => 'feature_unieval', | ||||
26 | declared_refs => 'feature_myref', | ||||
27 | unicode_strings => 'feature_unicode', | ||||
28 | multidimensional => 'feature_multidimensional', | ||||
29 | bareword_filehandles => 'feature_bareword_filehandles', | ||||
30 | extra_paired_delimiters => 'feature_more_delims', | ||||
31 | ); | ||||
32 | |||||
33 | 1 | 5µs | our %feature_bundle = ( | ||
34 | "5.10" => [qw(bareword_filehandles indirect multidimensional say state switch)], | ||||
35 | "5.11" => [qw(bareword_filehandles indirect multidimensional say state switch unicode_strings)], | ||||
36 | "5.15" => [qw(bareword_filehandles current_sub evalbytes fc indirect multidimensional say state switch unicode_eval unicode_strings)], | ||||
37 | "5.23" => [qw(bareword_filehandles current_sub evalbytes fc indirect multidimensional postderef_qq say state switch unicode_eval unicode_strings)], | ||||
38 | "5.27" => [qw(bareword_filehandles bitwise current_sub evalbytes fc indirect multidimensional postderef_qq say state switch unicode_eval unicode_strings)], | ||||
39 | "5.35" => [qw(bareword_filehandles bitwise current_sub evalbytes fc isa postderef_qq say signatures state unicode_eval unicode_strings)], | ||||
40 | "all" => [qw(bareword_filehandles bitwise current_sub declared_refs defer evalbytes extra_paired_delimiters fc indirect isa multidimensional postderef_qq refaliasing say signatures state switch try unicode_eval unicode_strings)], | ||||
41 | "default" => [qw(bareword_filehandles indirect multidimensional)], | ||||
42 | ); | ||||
43 | |||||
44 | 1 | 400ns | $feature_bundle{"5.12"} = $feature_bundle{"5.11"}; | ||
45 | 1 | 200ns | $feature_bundle{"5.13"} = $feature_bundle{"5.11"}; | ||
46 | 1 | 200ns | $feature_bundle{"5.14"} = $feature_bundle{"5.11"}; | ||
47 | 1 | 500ns | $feature_bundle{"5.16"} = $feature_bundle{"5.15"}; | ||
48 | 1 | 200ns | $feature_bundle{"5.17"} = $feature_bundle{"5.15"}; | ||
49 | 1 | 100ns | $feature_bundle{"5.18"} = $feature_bundle{"5.15"}; | ||
50 | 1 | 100ns | $feature_bundle{"5.19"} = $feature_bundle{"5.15"}; | ||
51 | 1 | 200ns | $feature_bundle{"5.20"} = $feature_bundle{"5.15"}; | ||
52 | 1 | 100ns | $feature_bundle{"5.21"} = $feature_bundle{"5.15"}; | ||
53 | 1 | 100ns | $feature_bundle{"5.22"} = $feature_bundle{"5.15"}; | ||
54 | 1 | 100ns | $feature_bundle{"5.24"} = $feature_bundle{"5.23"}; | ||
55 | 1 | 100ns | $feature_bundle{"5.25"} = $feature_bundle{"5.23"}; | ||
56 | 1 | 100ns | $feature_bundle{"5.26"} = $feature_bundle{"5.23"}; | ||
57 | 1 | 700ns | $feature_bundle{"5.28"} = $feature_bundle{"5.27"}; | ||
58 | 1 | 100ns | $feature_bundle{"5.29"} = $feature_bundle{"5.27"}; | ||
59 | 1 | 100ns | $feature_bundle{"5.30"} = $feature_bundle{"5.27"}; | ||
60 | 1 | 100ns | $feature_bundle{"5.31"} = $feature_bundle{"5.27"}; | ||
61 | 1 | 100ns | $feature_bundle{"5.32"} = $feature_bundle{"5.27"}; | ||
62 | 1 | 100ns | $feature_bundle{"5.33"} = $feature_bundle{"5.27"}; | ||
63 | 1 | 100ns | $feature_bundle{"5.34"} = $feature_bundle{"5.27"}; | ||
64 | 1 | 200ns | $feature_bundle{"5.36"} = $feature_bundle{"5.35"}; | ||
65 | 1 | 100ns | $feature_bundle{"5.9.5"} = $feature_bundle{"5.10"}; | ||
66 | 1 | 900ns | my %noops = ( | ||
67 | postderef => 1, | ||||
68 | lexical_subs => 1, | ||||
69 | ); | ||||
70 | 1 | 600ns | my %removed = ( | ||
71 | array_base => 1, | ||||
72 | ); | ||||
73 | |||||
74 | 1 | 100ns | our $hint_shift = 26; | ||
75 | 1 | 100ns | our $hint_mask = 0x3c000000; | ||
76 | 1 | 700ns | our @hint_bundles = qw( default 5.10 5.11 5.15 5.23 5.27 5.35 ); | ||
77 | |||||
78 | # This gets set (for now) in $^H as well as in %^H, | ||||
79 | # for runtime speed of the uc/lc/ucfirst/lcfirst functions. | ||||
80 | # See HINT_UNI_8_BIT in perl.h. | ||||
81 | 1 | 200ns | our $hint_uni8bit = 0x00000800; | ||
82 | |||||
83 | # TODO: | ||||
84 | # - think about versioned features (use feature switch => 2) | ||||
85 | |||||
86 | # spent 100µs (9+91) within feature::import which was called 3 times, avg 34µs/call:
# once (3µs+34µs) by Gradescope::Translate::BEGIN@12 at line 12 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/lib/Gradescope/Translate.pm
# once (4µs+29µs) by main::BEGIN@43 at line 43 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/bin/split.pl
# once (2µs+28µs) by Gradescope::Color::BEGIN@12 at line 12 of /home/hejohns/documentsNoSync/22f/490/gradescope-utils/lib/Gradescope/Color.pm | ||||
87 | 3 | 300ns | shift; | ||
88 | |||||
89 | 3 | 800ns | if (!@_) { | ||
90 | croak("No features specified"); | ||||
91 | } | ||||
92 | |||||
93 | 3 | 7µs | 3 | 91µs | __common(1, @_); # spent 91µs making 3 calls to feature::__common, avg 30µs/call |
94 | } | ||||
95 | |||||
96 | sub unimport { | ||||
97 | shift; | ||||
98 | |||||
99 | # A bare C<no feature> should reset to the default bundle | ||||
100 | if (!@_) { | ||||
101 | $^H &= ~($hint_uni8bit|$hint_mask); | ||||
102 | return; | ||||
103 | } | ||||
104 | |||||
105 | __common(0, @_); | ||||
106 | } | ||||
107 | |||||
108 | # spent 91µs within feature::__common which was called 3 times, avg 30µs/call:
# 3 times (91µs+0s) by feature::import at line 93, avg 30µs/call | ||||
109 | 3 | 600ns | my $import = shift; | ||
110 | 3 | 2µs | my $bundle_number = $^H & $hint_mask; | ||
111 | my $features = $bundle_number != $hint_mask | ||||
112 | 3 | 2µs | && $feature_bundle{$hint_bundles[$bundle_number >> $hint_shift]}; | ||
113 | 3 | 900ns | if ($features) { | ||
114 | # Features are enabled implicitly via bundle hints. | ||||
115 | # Delete any keys that may be left over from last time. | ||||
116 | 3 | 42µs | delete @^H{ values(%feature) }; | ||
117 | 3 | 1µs | $^H |= $hint_mask; | ||
118 | 3 | 2µs | for (@$features) { | ||
119 | 36 | 23µs | $^H{$feature{$_}} = 1; | ||
120 | 36 | 7µs | $^H |= $hint_uni8bit if $_ eq 'unicode_strings'; | ||
121 | } | ||||
122 | } | ||||
123 | 3 | 6µs | while (@_) { | ||
124 | 3 | 700ns | my $name = shift; | ||
125 | 3 | 2µs | if (substr($name, 0, 1) eq ":") { | ||
126 | my $v = substr($name, 1); | ||||
127 | if (!exists $feature_bundle{$v}) { | ||||
128 | $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/; | ||||
129 | if (!exists $feature_bundle{$v}) { | ||||
130 | unknown_feature_bundle(substr($name, 1)); | ||||
131 | } | ||||
132 | } | ||||
133 | unshift @_, @{$feature_bundle{$v}}; | ||||
134 | next; | ||||
135 | } | ||||
136 | 3 | 800ns | if (!exists $feature{$name}) { | ||
137 | if (exists $noops{$name}) { | ||||
138 | next; | ||||
139 | } | ||||
140 | if (!$import && exists $removed{$name}) { | ||||
141 | next; | ||||
142 | } | ||||
143 | unknown_feature($name); | ||||
144 | } | ||||
145 | 3 | 2µs | if ($import) { | ||
146 | 3 | 2µs | $^H{$feature{$name}} = 1; | ||
147 | 3 | 400ns | $^H |= $hint_uni8bit if $name eq 'unicode_strings'; | ||
148 | } else { | ||||
149 | delete $^H{$feature{$name}}; | ||||
150 | $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings'; | ||||
151 | } | ||||
152 | } | ||||
153 | } | ||||
154 | |||||
155 | sub unknown_feature { | ||||
156 | my $feature = shift; | ||||
157 | croak(sprintf('Feature "%s" is not supported by Perl %vd', | ||||
158 | $feature, $^V)); | ||||
159 | } | ||||
160 | |||||
161 | sub unknown_feature_bundle { | ||||
162 | my $feature = shift; | ||||
163 | croak(sprintf('Feature bundle "%s" is not supported by Perl %vd', | ||||
164 | $feature, $^V)); | ||||
165 | } | ||||
166 | |||||
167 | sub croak { | ||||
168 | require Carp; | ||||
169 | Carp::croak(@_); | ||||
170 | } | ||||
171 | |||||
172 | sub features_enabled { | ||||
173 | my ($depth) = @_; | ||||
174 | |||||
175 | $depth //= 1; | ||||
176 | my @frame = caller($depth+1) | ||||
177 | or return; | ||||
178 | my ($hints, $hinthash) = @frame[8, 10]; | ||||
179 | |||||
180 | my $bundle_number = $hints & $hint_mask; | ||||
181 | if ($bundle_number != $hint_mask) { | ||||
182 | return $feature_bundle{$hint_bundles[$bundle_number >> $hint_shift]}->@*; | ||||
183 | } | ||||
184 | else { | ||||
185 | my @features; | ||||
186 | for my $feature (sort keys %feature) { | ||||
187 | if ($hinthash->{$feature{$feature}}) { | ||||
188 | push @features, $feature; | ||||
189 | } | ||||
190 | } | ||||
191 | return @features; | ||||
192 | } | ||||
193 | } | ||||
194 | |||||
195 | sub feature_enabled { | ||||
196 | my ($feature, $depth) = @_; | ||||
197 | |||||
198 | $depth //= 1; | ||||
199 | my @frame = caller($depth+1) | ||||
200 | or return; | ||||
201 | my ($hints, $hinthash) = @frame[8, 10]; | ||||
202 | |||||
203 | my $hint_feature = $feature{$feature} | ||||
204 | or croak "Unknown feature $feature"; | ||||
205 | my $bundle_number = $hints & $hint_mask; | ||||
206 | if ($bundle_number != $hint_mask) { | ||||
207 | my $bundle = $hint_bundles[$bundle_number >> $hint_shift]; | ||||
208 | for my $bundle_feature ($feature_bundle{$bundle}->@*) { | ||||
209 | return 1 if $bundle_feature eq $feature; | ||||
210 | } | ||||
211 | return 0; | ||||
212 | } | ||||
213 | else { | ||||
214 | return $hinthash->{$hint_feature} // 0; | ||||
215 | } | ||||
216 | } | ||||
217 | |||||
218 | sub feature_bundle { | ||||
219 | my $depth = shift; | ||||
220 | |||||
221 | $depth //= 1; | ||||
222 | my @frame = caller($depth+1) | ||||
223 | or return; | ||||
224 | my $bundle_number = $frame[8] & $hint_mask; | ||||
225 | if ($bundle_number != $hint_mask) { | ||||
226 | return $hint_bundles[$bundle_number >> $hint_shift]; | ||||
227 | } | ||||
228 | else { | ||||
229 | return undef; | ||||
230 | } | ||||
231 | } | ||||
232 | |||||
233 | 1 | 17µs | 1; | ||
234 | |||||
235 | # ex: set ro: |