Filename | /usr/lib64/perl5/5.16.0/constant.pm |
Statements | Executed 2441 statements in 28.7ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
92 | 92 | 13 | 15.5ms | 19.3ms | import | constant::
112 | 1 | 1 | 1.32ms | 1.32ms | CORE:match (opcode) | constant::
1 | 1 | 1 | 1.17ms | 1.17ms | BEGIN@36 | constant::
115 | 4 | 1 | 805µs | 805µs | CORE:regcomp (opcode) | constant::
1 | 1 | 1 | 764µs | 84.0ms | BEGIN@25 | constant::
1 | 1 | 1 | 96µs | 96µs | BEGIN@2 | constant::
1 | 1 | 1 | 68µs | 165µs | BEGIN@3 | constant::
1 | 1 | 1 | 60µs | 144µs | BEGIN@65 | constant::
1 | 1 | 1 | 58µs | 133µs | BEGIN@127 | constant::
1 | 1 | 1 | 54µs | 130µs | BEGIN@29 | constant::
1 | 1 | 1 | 53µs | 278µs | BEGIN@6 | constant::
1 | 1 | 1 | 52µs | 671µs | BEGIN@4 | constant::
3 | 3 | 1 | 30µs | 30µs | CORE:qr (opcode) | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:151] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:155] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:157] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:31] | constant::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package constant; | ||||
2 | 2 | 279µs | 1 | 96µs | # spent 96µs within constant::BEGIN@2 which was called:
# once (96µs+0s) by File::Which::BEGIN@16 at line 2 # spent 96µs making 1 call to constant::BEGIN@2 |
3 | 2 | 146µs | 2 | 262µs | # spent 165µs (68+97) within constant::BEGIN@3 which was called:
# once (68µs+97µs) by File::Which::BEGIN@16 at line 3 # spent 165µs making 1 call to constant::BEGIN@3
# spent 97µs making 1 call to strict::import |
4 | 2 | 340µs | 2 | 1.29ms | # spent 671µs (52+619) within constant::BEGIN@4 which was called:
# once (52µs+619µs) by File::Which::BEGIN@16 at line 4 # spent 671µs making 1 call to constant::BEGIN@4
# spent 619µs making 1 call to warnings::register::import |
5 | |||||
6 | 2 | 722µs | 2 | 502µs | # spent 278µs (53+224) within constant::BEGIN@6 which was called:
# once (53µs+224µs) by File::Which::BEGIN@16 at line 6 # spent 278µs making 1 call to constant::BEGIN@6
# spent 224µs making 1 call to vars::import |
7 | 1 | 4µs | $VERSION = '1.23'; | ||
8 | |||||
9 | #======================================================================= | ||||
10 | |||||
11 | # Some names are evil choices. | ||||
12 | 1 | 33µs | my %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD }; | ||
13 | 1 | 10µs | $keywords{UNITCHECK}++ if $] > 5.009; | ||
14 | |||||
15 | 1 | 33µs | my %forced_into_main = map +($_, 1), | ||
16 | qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG }; | ||||
17 | |||||
18 | 1 | 26µs | my %forbidden = (%keywords, %forced_into_main); | ||
19 | |||||
20 | 1 | 4µs | my $str_end = $] >= 5.006 ? "\\z" : "\\Z"; | ||
21 | 1 | 164µs | 2 | 94µs | my $normal_constant_name = qr/^_?[^\W_0-9]\w*$str_end/; # spent 80µs making 1 call to constant::CORE:regcomp
# spent 13µs making 1 call to constant::CORE:qr |
22 | 1 | 68µs | 2 | 34µs | my $tolerable = qr/^[A-Za-z_]\w*$str_end/; # spent 25µs making 1 call to constant::CORE:regcomp
# spent 9µs making 1 call to constant::CORE:qr |
23 | 1 | 69µs | 2 | 35µs | my $boolean = qr/^[01]?$str_end/; # spent 26µs making 1 call to constant::CORE:regcomp
# spent 8µs making 1 call to constant::CORE:qr |
24 | |||||
25 | # spent 84.0ms (764µs+83.3) within constant::BEGIN@25 which was called:
# once (764µs+83.3ms) by File::Which::BEGIN@16 at line 45 | ||||
26 | # We'd like to do use constant _CAN_PCS => $] > 5.009002 | ||||
27 | # but that's a bit tricky before we load the constant module :-) | ||||
28 | # By doing this, we save 1 run time check for *every* call to import. | ||||
29 | 2 | 930µs | 2 | 207µs | # spent 130µs (54+76) within constant::BEGIN@29 which was called:
# once (54µs+76µs) by File::Which::BEGIN@16 at line 29 # spent 130µs making 1 call to constant::BEGIN@29
# spent 76µs making 1 call to strict::unimport |
30 | 1 | 8µs | my $const = $] > 5.009002; | ||
31 | 1 | 29µs | *_CAN_PCS = sub () {$const}; | ||
32 | |||||
33 | # Before this makes its way into a dev perl release, we have to do | ||||
34 | # browser-sniffing, as it were.... | ||||
35 | 1 | 900ns | return unless $const; | ||
36 | 3 | 1.70ms | 1 | 20.6ms | # spent 1.17ms within constant::BEGIN@36 which was called:
# once (1.17ms+0s) by constant::BEGIN@25 at line 45 # spent 20.6ms making 1 call to utf8::AUTOLOAD |
37 | 1 | 32µs | if (exists ${__PACKAGE__."::"}{"\xc4\x80"}) { | ||
38 | delete ${__PACKAGE__."::"}{"\xc4\x80"}; | ||||
39 | *_DOWNGRADE = sub () {1}; | ||||
40 | } | ||||
41 | else { | ||||
42 | 1 | 9µs | delete ${__PACKAGE__."::"}{chr 256}; | ||
43 | 1 | 9µs | *_DOWNGRADE = sub () {0}; | ||
44 | } | ||||
45 | 1 | 519µs | 2 | 85.2ms | } # spent 84.0ms making 1 call to constant::BEGIN@25
# spent 1.17ms making 1 call to constant::BEGIN@36 |
46 | |||||
47 | #======================================================================= | ||||
48 | # import() - import symbols into user's namespace | ||||
49 | # | ||||
50 | # What we actually do is define a function in the caller's namespace | ||||
51 | # which returns the value. The function we create will normally | ||||
52 | # be inlined as a constant, thereby avoiding further sub calling | ||||
53 | # overhead. | ||||
54 | #======================================================================= | ||||
55 | # spent 19.3ms (15.5+3.70) within constant::import which was called 92 times, avg 209µs/call:
# once (1.67ms+455µs) by XML::LibXML::BEGIN@235 at line 236 of XML/LibXML.pm
# once (261µs+68µs) by Data::Dumper::BEGIN@275 at line 275 of Data/Dumper.pm
# once (220µs+59µs) by File::Which::BEGIN@16 at line 16 of File/Which.pm
# once (212µs+56µs) by JSON::Backend::XS::BEGIN@9 at line 9 of (eval 18)[JSON.pm:268]
# once (200µs+46µs) by Encode::Alias::BEGIN@6 at line 6 of Encode/Alias.pm
# once (198µs+47µs) by Getopt::Long::BEGIN@208 at line 208 of Getopt/Long.pm
# once (192µs+47µs) by XML::SAX::BEGIN@20 at line 20 of XML/SAX.pm
# once (187µs+51µs) by XML::LibXML::BEGIN@160 at line 160 of XML/LibXML.pm
# once (180µs+58µs) by Encode::BEGIN@8 at line 8 of Encode.pm
# once (201µs+35µs) by XML::LibXML::Error::BEGIN@35 at line 35 of XML/LibXML/Error.pm
# once (186µs+48µs) by IPC::Run3::BEGIN@41 at line 41 of IPC/Run3.pm
# once (182µs+46µs) by RTP::Webmerge::Embedder::PHP::BEGIN@26 at line 26 of webmerge/scripts/modules/RTP/Webmerge/Embedder/PHP.pm
# once (183µs+45µs) by File::Temp::BEGIN@217 at line 217 of File/Temp.pm
# once (178µs+44µs) by XML::LibXML::Error::BEGIN@34 at line 34 of XML/LibXML/Error.pm
# once (181µs+42µs) by XML::LibXML::BEGIN@21 at line 21 of XML/LibXML.pm
# once (177µs+44µs) by RTP::Webmerge::Embedder::JS::BEGIN@26 at line 26 of webmerge/scripts/modules/RTP/Webmerge/Embedder/JS.pm
# once (186µs+32µs) by IPC::Run3::BEGIN@42 at line 42 of IPC/Run3.pm
# once (178µs+34µs) by XML::LibXML::Error::BEGIN@57 at line 57 of XML/LibXML/Error.pm
# once (179µs+32µs) by XML::LibXML::Error::BEGIN@61 at line 61 of XML/LibXML/Error.pm
# once (174µs+37µs) by Getopt::Long::BEGIN@237 at line 237 of Getopt/Long.pm
# once (175µs+32µs) by XML::LibXML::BEGIN@22 at line 22 of XML/LibXML.pm
# once (135µs+70µs) by XML::LibXML::BEGIN@164 at line 164 of XML/LibXML.pm
# once (163µs+40µs) by File::Which::BEGIN@18 at line 18 of File/Which.pm
# once (169µs+30µs) by XML::LibXML::BEGIN@175 at line 175 of XML/LibXML.pm
# once (157µs+42µs) by File::Which::BEGIN@17 at line 17 of File/Which.pm
# once (148µs+43µs) by XML::LibXML::Error::BEGIN@52 at line 52 of XML/LibXML/Error.pm
# once (154µs+37µs) by XML::LibXML::Error::BEGIN@47 at line 47 of XML/LibXML/Error.pm
# once (156µs+34µs) by XML::LibXML::Error::BEGIN@66 at line 66 of XML/LibXML/Error.pm
# once (156µs+34µs) by XML::LibXML::Error::BEGIN@54 at line 54 of XML/LibXML/Error.pm
# once (154µs+35µs) by JSON::Backend::XS::BEGIN@11 at line 11 of (eval 18)[JSON.pm:268]
# once (144µs+46µs) by Getopt::Long::BEGIN@224 at line 224 of Getopt/Long.pm
# once (153µs+34µs) by IPC::Run3::BEGIN@43 at line 43 of IPC/Run3.pm
# once (155µs+32µs) by Getopt::Long::BEGIN@229 at line 229 of Getopt/Long.pm
# once (156µs+30µs) by XML::LibXML::Error::BEGIN@51 at line 51 of XML/LibXML/Error.pm
# once (151µs+35µs) by Getopt::Long::BEGIN@218 at line 218 of Getopt/Long.pm
# once (154µs+32µs) by XML::LibXML::BEGIN@172 at line 172 of XML/LibXML.pm
# once (154µs+32µs) by XML::LibXML::Error::BEGIN@64 at line 64 of XML/LibXML/Error.pm
# once (136µs+47µs) by File::Temp::BEGIN@230 at line 230 of File/Temp.pm
# once (149µs+33µs) by XML::LibXML::BEGIN@161 at line 161 of XML/LibXML.pm
# once (147µs+34µs) by XML::LibXML::Error::BEGIN@65 at line 65 of XML/LibXML/Error.pm
# once (143µs+36µs) by XML::LibXML::Error::BEGIN@58 at line 58 of XML/LibXML/Error.pm
# once (145µs+34µs) by XML::SAX::BEGIN@22 at line 22 of XML/SAX.pm
# once (143µs+34µs) by XML::LibXML::Error::BEGIN@46 at line 46 of XML/LibXML/Error.pm
# once (142µs+35µs) by XML::LibXML::Error::BEGIN@62 at line 62 of XML/LibXML/Error.pm
# once (145µs+30µs) by Getopt::Long::BEGIN@247 at line 247 of Getopt/Long.pm
# once (143µs+32µs) by XML::LibXML::Error::BEGIN@53 at line 53 of XML/LibXML/Error.pm
# once (140µs+34µs) by Getopt::Long::BEGIN@236 at line 236 of Getopt/Long.pm
# once (143µs+31µs) by XML::LibXML::Error::BEGIN@67 at line 67 of XML/LibXML/Error.pm
# once (141µs+33µs) by XML::LibXML::Error::BEGIN@48 at line 48 of XML/LibXML/Error.pm
# once (140µs+33µs) by XML::LibXML::BEGIN@165 at line 165 of XML/LibXML.pm
# once (138µs+35µs) by XML::LibXML::Error::BEGIN@36 at line 36 of XML/LibXML/Error.pm
# once (140µs+32µs) by XML::LibXML::Error::BEGIN@45 at line 45 of XML/LibXML/Error.pm
# once (140µs+32µs) by XML::LibXML::BEGIN@176 at line 176 of XML/LibXML.pm
# once (139µs+33µs) by XML::LibXML::Error::BEGIN@37 at line 37 of XML/LibXML/Error.pm
# once (138µs+34µs) by XML::LibXML::Error::BEGIN@55 at line 55 of XML/LibXML/Error.pm
# once (140µs+32µs) by XML::LibXML::BEGIN@179 at line 179 of XML/LibXML.pm
# once (139µs+32µs) by XML::LibXML::Error::BEGIN@39 at line 39 of XML/LibXML/Error.pm
# once (139µs+31µs) by XML::SAX::BEGIN@23 at line 23 of XML/SAX.pm
# once (138µs+32µs) by Getopt::Long::BEGIN@225 at line 225 of Getopt/Long.pm
# once (138µs+31µs) by XML::LibXML::Error::BEGIN@40 at line 40 of XML/LibXML/Error.pm
# once (138µs+31µs) by XML::LibXML::Error::BEGIN@59 at line 59 of XML/LibXML/Error.pm
# once (139µs+30µs) by Getopt::Long::BEGIN@223 at line 223 of Getopt/Long.pm
# once (136µs+32µs) by XML::LibXML::BEGIN@166 at line 166 of XML/LibXML.pm
# once (137µs+31µs) by XML::LibXML::Error::BEGIN@63 at line 63 of XML/LibXML/Error.pm
# once (136µs+32µs) by File::Temp::BEGIN@220 at line 220 of File/Temp.pm
# once (138µs+30µs) by XML::LibXML::Error::BEGIN@49 at line 49 of XML/LibXML/Error.pm
# once (137µs+31µs) by XML::LibXML::BEGIN@177 at line 177 of XML/LibXML.pm
# once (136µs+31µs) by JSON::Backend::XS::BEGIN@18 at line 18 of (eval 18)[JSON.pm:268]
# once (135µs+32µs) by XML::LibXML::Error::BEGIN@43 at line 43 of XML/LibXML/Error.pm
# once (137µs+30µs) by XML::LibXML::BEGIN@162 at line 162 of XML/LibXML.pm
# once (135µs+32µs) by File::Temp::BEGIN@224 at line 224 of File/Temp.pm
# once (136µs+30µs) by XML::LibXML::Error::BEGIN@42 at line 42 of XML/LibXML/Error.pm
# once (137µs+30µs) by Getopt::Long::BEGIN@228 at line 228 of Getopt/Long.pm
# once (136µs+30µs) by XML::LibXML::Error::BEGIN@60 at line 60 of XML/LibXML/Error.pm
# once (137µs+30µs) by XML::LibXML::BEGIN@174 at line 174 of XML/LibXML.pm
# once (137µs+30µs) by File::Temp::BEGIN@229 at line 229 of File/Temp.pm
# once (136µs+30µs) by XML::LibXML::Error::BEGIN@44 at line 44 of XML/LibXML/Error.pm
# once (137µs+29µs) by XML::LibXML::BEGIN@173 at line 173 of XML/LibXML.pm
# once (136µs+30µs) by Getopt::Long::BEGIN@220 at line 220 of Getopt/Long.pm
# once (136µs+30µs) by XML::LibXML::Error::BEGIN@50 at line 50 of XML/LibXML/Error.pm
# once (136µs+30µs) by XML::LibXML::Error::BEGIN@41 at line 41 of XML/LibXML/Error.pm
# once (137µs+28µs) by Getopt::Long::BEGIN@222 at line 222 of Getopt/Long.pm
# once (136µs+29µs) by XML::LibXML::BEGIN@167 at line 167 of XML/LibXML.pm
# once (135µs+29µs) by XML::LibXML::BEGIN@178 at line 178 of XML/LibXML.pm
# once (134µs+30µs) by XML::LibXML::Error::BEGIN@56 at line 56 of XML/LibXML/Error.pm
# once (135µs+28µs) by Getopt::Long::BEGIN@226 at line 226 of Getopt/Long.pm
# once (133µs+29µs) by XML::LibXML::BEGIN@163 at line 163 of XML/LibXML.pm
# once (131µs+31µs) by File::Temp::BEGIN@228 at line 228 of File/Temp.pm
# once (130µs+31µs) by XML::LibXML::BEGIN@169 at line 169 of XML/LibXML.pm
# once (132µs+29µs) by XML::LibXML::BEGIN@170 at line 170 of XML/LibXML.pm
# once (132µs+29µs) by XML::LibXML::BEGIN@168 at line 168 of XML/LibXML.pm
# once (131µs+29µs) by XML::LibXML::BEGIN@171 at line 171 of XML/LibXML.pm | ||||
56 | 92 | 254µs | my $class = shift; | ||
57 | 92 | 178µs | return unless @_; # Ignore 'use constant;' | ||
58 | 92 | 58µs | my $constants; | ||
59 | 92 | 210µs | my $multiple = ref $_[0]; | ||
60 | 92 | 372µs | my $pkg = caller; | ||
61 | 92 | 57µs | my $flush_mro; | ||
62 | 92 | 61µs | my $symtab; | ||
63 | |||||
64 | 92 | 229µs | if (_CAN_PCS) { | ||
65 | 2 | 1.57ms | 2 | 227µs | # spent 144µs (60+83) within constant::BEGIN@65 which was called:
# once (60µs+83µs) by File::Which::BEGIN@16 at line 65 # spent 144µs making 1 call to constant::BEGIN@65
# spent 83µs making 1 call to strict::unimport |
66 | 92 | 842µs | $symtab = \%{$pkg . '::'}; | ||
67 | }; | ||||
68 | |||||
69 | 92 | 181µs | if ( $multiple ) { | ||
70 | 1 | 6µs | if (ref $_[0] ne 'HASH') { | ||
71 | require Carp; | ||||
72 | Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'"); | ||||
73 | } | ||||
74 | 1 | 2µs | $constants = shift; | ||
75 | } else { | ||||
76 | 91 | 132µs | unless (defined $_[0]) { | ||
77 | require Carp; | ||||
78 | Carp::croak("Can't use undef as constant name"); | ||||
79 | } | ||||
80 | 91 | 738µs | $constants->{+shift} = undef; | ||
81 | } | ||||
82 | |||||
83 | 92 | 924µs | foreach my $name ( keys %$constants ) { | ||
84 | # Normal constant name | ||||
85 | 112 | 5.21ms | 224 | 1.99ms | if ($name =~ $normal_constant_name and !$forbidden{$name}) { # spent 1.32ms making 112 calls to constant::CORE:match, avg 12µs/call
# spent 673µs making 112 calls to constant::CORE:regcomp, avg 6µs/call |
86 | # Everything is okay | ||||
87 | |||||
88 | # Name forced into main, but we're not in main. Fatal. | ||||
89 | } elsif ($forced_into_main{$name} and $pkg ne 'main') { | ||||
90 | require Carp; | ||||
91 | Carp::croak("Constant name '$name' is forced into main::"); | ||||
92 | |||||
93 | # Starts with double underscore. Fatal. | ||||
94 | } elsif ($name =~ /^__/) { | ||||
95 | require Carp; | ||||
96 | Carp::croak("Constant name '$name' begins with '__'"); | ||||
97 | |||||
98 | # Maybe the name is tolerable | ||||
99 | } elsif ($name =~ $tolerable) { | ||||
100 | # Then we'll warn only if you've asked for warnings | ||||
101 | if (warnings::enabled()) { | ||||
102 | if ($keywords{$name}) { | ||||
103 | warnings::warn("Constant name '$name' is a Perl keyword"); | ||||
104 | } elsif ($forced_into_main{$name}) { | ||||
105 | warnings::warn("Constant name '$name' is " . | ||||
106 | "forced into package main::"); | ||||
107 | } | ||||
108 | } | ||||
109 | |||||
110 | # Looks like a boolean | ||||
111 | # use constant FRED == fred; | ||||
112 | } elsif ($name =~ $boolean) { | ||||
113 | require Carp; | ||||
114 | if (@_) { | ||||
115 | Carp::croak("Constant name '$name' is invalid"); | ||||
116 | } else { | ||||
117 | Carp::croak("Constant name looks like boolean value"); | ||||
118 | } | ||||
119 | |||||
120 | } else { | ||||
121 | # Must have bad characters | ||||
122 | require Carp; | ||||
123 | Carp::croak("Constant name '$name' has invalid characters"); | ||||
124 | } | ||||
125 | |||||
126 | { | ||||
127 | 114 | 2.23ms | 2 | 208µs | # spent 133µs (58+75) within constant::BEGIN@127 which was called:
# once (58µs+75µs) by File::Which::BEGIN@16 at line 127 # spent 133µs making 1 call to constant::BEGIN@127
# spent 75µs making 1 call to strict::unimport |
128 | 112 | 471µs | my $full_name = "${pkg}::$name"; | ||
129 | 112 | 777µs | $declared{$full_name}++; | ||
130 | 112 | 426µs | if ($multiple || @_ == 1) { | ||
131 | 112 | 259µs | my $scalar = $multiple ? $constants->{$name} : $_[0]; | ||
132 | |||||
133 | if (_DOWNGRADE) { # for 5.10 to 5.14 | ||||
134 | # Work around perl bug #31991: Sub names (actually glob | ||||
135 | # names in general) ignore the UTF8 flag. So we have to | ||||
136 | # turn it off to get the "right" symbol table entry. | ||||
137 | utf8::is_utf8 $name and utf8::encode $name; | ||||
138 | } | ||||
139 | |||||
140 | # The constant serves to optimise this entire block out on | ||||
141 | # 5.8 and earlier. | ||||
142 | 112 | 559µs | if (_CAN_PCS && $symtab && !exists $symtab->{$name}) { | ||
143 | # No typeglob yet, so we can use a reference as space- | ||||
144 | # efficient proxy for a constant subroutine | ||||
145 | # The check in Perl_ck_rvconst knows that inlinable | ||||
146 | # constants from cv_const_sv are read only. So we have to: | ||||
147 | 112 | 2.29ms | 112 | 711µs | Internals::SvREADONLY($scalar, 1); # spent 711µs making 112 calls to Internals::SvREADONLY, avg 6µs/call |
148 | 112 | 602µs | $symtab->{$name} = \$scalar; | ||
149 | 112 | 295µs | ++$flush_mro; | ||
150 | } else { | ||||
151 | *$full_name = sub () { $scalar }; | ||||
152 | } | ||||
153 | } elsif (@_) { | ||||
154 | my @list = @_; | ||||
155 | *$full_name = sub () { @list }; | ||||
156 | } else { | ||||
157 | *$full_name = sub () { }; | ||||
158 | } | ||||
159 | } | ||||
160 | } | ||||
161 | # Flush the cache exactly once if we make any direct symbol table changes. | ||||
162 | 92 | 4.64ms | 92 | 1.00ms | mro::method_changed_in($pkg) if _CAN_PCS && $flush_mro; # spent 1.00ms making 92 calls to mro::method_changed_in, avg 11µs/call |
163 | } | ||||
164 | |||||
165 | 1 | 46µs | 1; | ||
166 | |||||
167 | __END__ | ||||
# spent 1.32ms within constant::CORE:match which was called 112 times, avg 12µs/call:
# 112 times (1.32ms+0s) by constant::import at line 85, avg 12µs/call | |||||
sub constant::CORE:qr; # opcode | |||||
# spent 805µs within constant::CORE:regcomp which was called 115 times, avg 7µs/call:
# 112 times (673µs+0s) by constant::import at line 85, avg 6µs/call
# once (80µs+0s) by File::Which::BEGIN@16 at line 21
# once (26µs+0s) by File::Which::BEGIN@16 at line 23
# once (25µs+0s) by File::Which::BEGIN@16 at line 22 |