Filename | /usr/share/perl/5.14/constant.pm |
Statements | Executed 1080 statements in 6.10ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
39 | 39 | 26 | 3.65ms | 4.39ms | import | constant::
46 | 4 | 1 | 212µs | 212µs | CORE:regcomp (opcode) | constant::
43 | 1 | 1 | 212µs | 212µs | CORE:match (opcode) | constant::
4 | 2 | 2 | 49µs | 49µs | __ANON__[:140] | constant::
1 | 1 | 1 | 32µs | 32µs | BEGIN@2 | constant::
1 | 1 | 1 | 24µs | 24µs | BEGIN@25 | constant::
1 | 1 | 1 | 19µs | 48µs | BEGIN@52 | constant::
1 | 1 | 1 | 18µs | 25µs | BEGIN@3 | constant::
1 | 1 | 1 | 16µs | 45µs | BEGIN@114 | constant::
1 | 1 | 1 | 16µs | 284µs | BEGIN@4 | constant::
3 | 3 | 1 | 15µs | 15µs | CORE:qr (opcode) | constant::
1 | 1 | 1 | 15µs | 45µs | BEGIN@29 | constant::
1 | 1 | 1 | 15µs | 89µs | BEGIN@6 | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:136] | constant::
0 | 0 | 0 | 0s | 0s | __ANON__[:142] | 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 | 71µs | 1 | 32µs | # spent 32µs within constant::BEGIN@2 which was called:
# once (32µs+0s) by CGI::Util::BEGIN@12 at line 2 # spent 32µs making 1 call to constant::BEGIN@2 |
3 | 2 | 50µs | 2 | 32µs | # spent 25µs (18+7) within constant::BEGIN@3 which was called:
# once (18µs+7µs) by CGI::Util::BEGIN@12 at line 3 # spent 25µs making 1 call to constant::BEGIN@3
# spent 7µs making 1 call to strict::import |
4 | 2 | 49µs | 2 | 552µs | # spent 284µs (16+268) within constant::BEGIN@4 which was called:
# once (16µs+268µs) by CGI::Util::BEGIN@12 at line 4 # spent 284µs making 1 call to constant::BEGIN@4
# spent 268µs making 1 call to warnings::register::import |
5 | |||||
6 | 2 | 215µs | 2 | 164µs | # spent 89µs (15+74) within constant::BEGIN@6 which was called:
# once (15µs+74µs) by CGI::Util::BEGIN@12 at line 6 # spent 89µs making 1 call to constant::BEGIN@6
# spent 74µs making 1 call to vars::import |
7 | 1 | 2µs | $VERSION = '1.21'; | ||
8 | |||||
9 | #======================================================================= | ||||
10 | |||||
11 | # Some names are evil choices. | ||||
12 | 1 | 8µs | my %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD }; | ||
13 | 1 | 3µs | $keywords{UNITCHECK}++ if $] > 5.009; | ||
14 | |||||
15 | 1 | 8µs | my %forced_into_main = map +($_, 1), | ||
16 | qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG }; | ||||
17 | |||||
18 | 1 | 11µs | my %forbidden = (%keywords, %forced_into_main); | ||
19 | |||||
20 | 1 | 2µs | my $str_end = $] >= 5.006 ? "\\z" : "\\Z"; | ||
21 | 1 | 45µs | 2 | 28µs | my $normal_constant_name = qr/^_?[^\W_0-9]\w*$str_end/; # spent 18µs making 1 call to constant::CORE:regcomp
# spent 10µs making 1 call to constant::CORE:qr |
22 | 1 | 21µs | 2 | 11µs | my $tolerable = qr/^[A-Za-z_]\w*$str_end/; # spent 9µs making 1 call to constant::CORE:regcomp
# spent 3µs making 1 call to constant::CORE:qr |
23 | 1 | 20µs | 2 | 11µs | my $boolean = qr/^[01]?$str_end/; # spent 8µs making 1 call to constant::CORE:regcomp
# spent 3µs making 1 call to constant::CORE:qr |
24 | |||||
25 | # spent 24µs within constant::BEGIN@25 which was called:
# once (24µs+0s) by CGI::Util::BEGIN@12 at line 32 | ||||
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 | 78µs | 2 | 75µs | # spent 45µs (15+30) within constant::BEGIN@29 which was called:
# once (15µs+30µs) by CGI::Util::BEGIN@12 at line 29 # spent 45µs making 1 call to constant::BEGIN@29
# spent 30µs making 1 call to strict::unimport |
30 | 1 | 3µs | my $const = $] > 5.009002; | ||
31 | 1 | 22µs | *_CAN_PCS = sub () {$const}; | ||
32 | 1 | 98µs | 1 | 24µs | } # spent 24µs making 1 call to constant::BEGIN@25 |
33 | |||||
34 | #======================================================================= | ||||
35 | # import() - import symbols into user's namespace | ||||
36 | # | ||||
37 | # What we actually do is define a function in the caller's namespace | ||||
38 | # which returns the value. The function we create will normally | ||||
39 | # be inlined as a constant, thereby avoiding further sub calling | ||||
40 | # overhead. | ||||
41 | #======================================================================= | ||||
42 | # spent 4.39ms (3.65+738µs) within constant::import which was called 39 times, avg 113µs/call:
# once (241µs+51µs) by Foswiki::Infix::Node::BEGIN@22 at line 23 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Infix/Node.pm
# once (128µs+25µs) by Foswiki::UI::BEGIN@165 at line 165 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/UI.pm
# once (121µs+29µs) by Foswiki::Plugins::JQueryPlugin::Plugin::BEGIN@9 at line 9 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Plugins/JQueryPlugin/Plugin.pm
# once (119µs+28µs) by Foswiki::Contrib::MailerContrib::Subscription::BEGIN@20 at line 20 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Contrib/MailerContrib/Subscription.pm
# once (121µs+25µs) by Time::Local::BEGIN@27 at line 27 of Time/Local.pm
# once (117µs+29µs) by Foswiki::Render::BEGIN@72 at line 72 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Render.pm
# once (111µs+25µs) by Foswiki::MetaCache::BEGIN@28 at line 28 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/MetaCache.pm
# once (109µs+24µs) by Foswiki::Query::HoistREs::BEGIN@58 at line 58 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/HoistREs.pm
# once (99µs+19µs) by Foswiki::Infix::Node::BEGIN@19 at line 19 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Infix/Node.pm
# once (88µs+25µs) by Foswiki::Validation::BEGIN@54 at line 54 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Validation.pm
# once (92µs+20µs) by Foswiki::Users::HtPasswdUser::BEGIN@26 at line 26 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Users/HtPasswdUser.pm
# once (94µs+18µs) by CGI::Util::BEGIN@12 at line 12 of CGI/Util.pm
# once (96µs+16µs) by Foswiki::Query::Parser::BEGIN@93 at line 93 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/Parser.pm
# once (89µs+22µs) by MultipartBuffer::BEGIN@3945 at line 3945 of CGI.pm
# once (90µs+20µs) by Foswiki::Iterator::BEGIN@26 at line 26 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Iterator.pm
# once (89µs+20µs) by Foswiki::Access::BEGIN@16 at line 16 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Access.pm
# once (90µs+19µs) by File::Temp::BEGIN@217 at line 217 of File/Temp.pm
# once (91µs+16µs) by Foswiki::Search::BEGIN@28 at line 28 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Search.pm
# once (88µs+16µs) by Foswiki::Access::TopicACLAccess::BEGIN@16 at line 16 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Access/TopicACLAccess.pm
# once (86µs+18µs) by Foswiki::Sandbox::BEGIN@45 at line 45 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Sandbox.pm
# once (85µs+17µs) by Foswiki::Store::Interfaces::QueryAlgorithm::BEGIN@23 at line 23 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/Interfaces/QueryAlgorithm.pm
# once (86µs+16µs) by Foswiki::Templates::BEGIN@42 at line 42 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Templates.pm
# once (83µs+17µs) by Foswiki::Infix::Parser::BEGIN@29 at line 29 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Infix/Parser.pm
# once (83µs+15µs) by Foswiki::Address::BEGIN@71 at line 71 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Address.pm
# once (81µs+16µs) by Foswiki::Store::QueryAlgorithms::BruteForce::BEGIN@46 at line 46 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Store/QueryAlgorithms/BruteForce.pm
# once (77µs+19µs) by Time::Local::BEGIN@29 at line 29 of Time/Local.pm
# once (81µs+13µs) by File::Temp::BEGIN@229 at line 229 of File/Temp.pm
# once (80µs+13µs) by Foswiki::Address::BEGIN@72 at line 72 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Address.pm
# once (79µs+14µs) by Foswiki::Query::Node::BEGIN@41 at line 41 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/Node.pm
# once (78µs+14µs) by Foswiki::Contrib::MailerContrib::Subscription::BEGIN@23 at line 23 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Contrib/MailerContrib/Subscription.pm
# once (77µs+15µs) by CGI::BEGIN@33 at line 33 of CGI.pm
# once (76µs+14µs) by File::Temp::BEGIN@220 at line 220 of File/Temp.pm
# once (77µs+13µs) by Foswiki::Address::BEGIN@73 at line 73 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Address.pm
# once (77µs+13µs) by Time::Local::BEGIN@28 at line 28 of Time/Local.pm
# once (76µs+13µs) by File::Temp::BEGIN@230 at line 230 of File/Temp.pm
# once (75µs+13µs) by File::Temp::BEGIN@228 at line 228 of File/Temp.pm
# once (75µs+13µs) by File::Temp::BEGIN@224 at line 224 of File/Temp.pm
# once (74µs+13µs) by Foswiki::Query::Node::BEGIN@42 at line 42 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/Node.pm
# once (74µs+11µs) by Foswiki::If::Parser::BEGIN@33 at line 33 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/If/Parser.pm | ||||
43 | 39 | 81µs | my $class = shift; | ||
44 | 39 | 65µs | return unless @_; # Ignore 'use constant;' | ||
45 | 39 | 50µs | my $constants; | ||
46 | 39 | 83µs | my $multiple = ref $_[0]; | ||
47 | 39 | 80µs | my $pkg = caller; | ||
48 | 39 | 42µs | my $flush_mro; | ||
49 | 39 | 41µs | my $symtab; | ||
50 | |||||
51 | 39 | 109µs | if (_CAN_PCS) { | ||
52 | 2 | 451µs | 2 | 77µs | # spent 48µs (19+29) within constant::BEGIN@52 which was called:
# once (19µs+29µs) by CGI::Util::BEGIN@12 at line 52 # spent 48µs making 1 call to constant::BEGIN@52
# spent 29µs making 1 call to strict::unimport |
53 | 78 | 267µs | $symtab = \%{$pkg . '::'}; | ||
54 | }; | ||||
55 | |||||
56 | 39 | 101µs | if ( $multiple ) { | ||
57 | 1 | 2µs | if (ref $_[0] ne 'HASH') { | ||
58 | require Carp; | ||||
59 | Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'"); | ||||
60 | } | ||||
61 | 1 | 1µs | $constants = shift; | ||
62 | } else { | ||||
63 | 38 | 58µs | unless (defined $_[0]) { | ||
64 | require Carp; | ||||
65 | Carp::croak("Can't use undef as constant name"); | ||||
66 | } | ||||
67 | 38 | 144µs | $constants->{+shift} = undef; | ||
68 | } | ||||
69 | |||||
70 | 39 | 200µs | foreach my $name ( keys %$constants ) { | ||
71 | # Normal constant name | ||||
72 | 43 | 910µs | 86 | 390µs | if ($name =~ $normal_constant_name and !$forbidden{$name}) { # spent 212µs making 43 calls to constant::CORE:match, avg 5µs/call
# spent 178µs making 43 calls to constant::CORE:regcomp, avg 4µs/call |
73 | # Everything is okay | ||||
74 | |||||
75 | # Name forced into main, but we're not in main. Fatal. | ||||
76 | } elsif ($forced_into_main{$name} and $pkg ne 'main') { | ||||
77 | require Carp; | ||||
78 | Carp::croak("Constant name '$name' is forced into main::"); | ||||
79 | |||||
80 | # Starts with double underscore. Fatal. | ||||
81 | } elsif ($name =~ /^__/) { | ||||
82 | require Carp; | ||||
83 | Carp::croak("Constant name '$name' begins with '__'"); | ||||
84 | |||||
85 | # Maybe the name is tolerable | ||||
86 | } elsif ($name =~ $tolerable) { | ||||
87 | # Then we'll warn only if you've asked for warnings | ||||
88 | if (warnings::enabled()) { | ||||
89 | if ($keywords{$name}) { | ||||
90 | warnings::warn("Constant name '$name' is a Perl keyword"); | ||||
91 | } elsif ($forced_into_main{$name}) { | ||||
92 | warnings::warn("Constant name '$name' is " . | ||||
93 | "forced into package main::"); | ||||
94 | } | ||||
95 | } | ||||
96 | |||||
97 | # Looks like a boolean | ||||
98 | # use constant FRED == fred; | ||||
99 | } elsif ($name =~ $boolean) { | ||||
100 | require Carp; | ||||
101 | if (@_) { | ||||
102 | Carp::croak("Constant name '$name' is invalid"); | ||||
103 | } else { | ||||
104 | Carp::croak("Constant name looks like boolean value"); | ||||
105 | } | ||||
106 | |||||
107 | } else { | ||||
108 | # Must have bad characters | ||||
109 | require Carp; | ||||
110 | Carp::croak("Constant name '$name' has invalid characters"); | ||||
111 | } | ||||
112 | |||||
113 | { | ||||
114 | 45 | 577µs | 2 | 74µs | # spent 45µs (16+29) within constant::BEGIN@114 which was called:
# once (16µs+29µs) by CGI::Util::BEGIN@12 at line 114 # spent 45µs making 1 call to constant::BEGIN@114
# spent 29µs making 1 call to strict::unimport |
115 | 43 | 110µs | my $full_name = "${pkg}::$name"; | ||
116 | 43 | 168µs | $declared{$full_name}++; | ||
117 | 43 | 138µs | if ($multiple || @_ == 1) { | ||
118 | 41 | 70µs | my $scalar = $multiple ? $constants->{$name} : $_[0]; | ||
119 | |||||
120 | # Work around perl bug #xxxxx: Sub names (actually glob | ||||
121 | # names in general) ignore the UTF8 flag. So we have to | ||||
122 | # turn it off to get the "right" symbol table entry. | ||||
123 | 41 | 331µs | 41 | 120µs | utf8::is_utf8 $name and utf8::encode $name; # spent 120µs making 41 calls to utf8::is_utf8, avg 3µs/call |
124 | |||||
125 | # The constant serves to optimise this entire block out on | ||||
126 | # 5.8 and earlier. | ||||
127 | 41 | 142µs | if (_CAN_PCS && $symtab && !exists $symtab->{$name}) { | ||
128 | # No typeglob yet, so we can use a reference as space- | ||||
129 | # efficient proxy for a constant subroutine | ||||
130 | # The check in Perl_ck_rvconst knows that inlinable | ||||
131 | # constants from cv_const_sv are read only. So we have to: | ||||
132 | 41 | 294µs | 41 | 95µs | Internals::SvREADONLY($scalar, 1); # spent 95µs making 41 calls to Internals::SvREADONLY, avg 2µs/call |
133 | 41 | 93µs | $symtab->{$name} = \$scalar; | ||
134 | 41 | 65µs | ++$flush_mro; | ||
135 | } else { | ||||
136 | *$full_name = sub () { $scalar }; | ||||
137 | } | ||||
138 | } elsif (@_) { | ||||
139 | 2 | 13µs | my @list = @_; | ||
140 | 6 | 71µs | # spent 49µs within constant::__ANON__[/usr/share/perl/5.14/constant.pm:140] which was called 4 times, avg 12µs/call:
# 3 times (42µs+0s) by Foswiki::Query::Parser::new at line 103 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/Query/Parser.pm, avg 14µs/call
# once (7µs+0s) by Foswiki::If::Parser::new at line 40 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/If/Parser.pm | ||
141 | } else { | ||||
142 | *$full_name = sub () { }; | ||||
143 | } | ||||
144 | } | ||||
145 | } | ||||
146 | # Flush the cache exactly once if we make any direct symbol table changes. | ||||
147 | 39 | 616µs | 37 | 134µs | mro::method_changed_in($pkg) if _CAN_PCS && $flush_mro; # spent 134µs making 37 calls to mro::method_changed_in, avg 4µs/call |
148 | } | ||||
149 | |||||
150 | 1 | 18µs | 1; | ||
151 | |||||
152 | __END__ | ||||
# spent 212µs within constant::CORE:match which was called 43 times, avg 5µs/call:
# 43 times (212µs+0s) by constant::import at line 72, avg 5µs/call | |||||
sub constant::CORE:qr; # opcode | |||||
# spent 212µs within constant::CORE:regcomp which was called 46 times, avg 5µs/call:
# 43 times (178µs+0s) by constant::import at line 72, avg 4µs/call
# once (18µs+0s) by CGI::Util::BEGIN@12 at line 21
# once (9µs+0s) by CGI::Util::BEGIN@12 at line 22
# once (8µs+0s) by CGI::Util::BEGIN@12 at line 23 |