Filename | /home/ss5/perl5/perlbrew/perls/tapper-perl/lib/5.16.3/constant.pm |
Statements | Executed 1099 statements in 2.30ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
37 | 37 | 7 | 944µs | 1.15ms | import | constant::
1 | 1 | 1 | 165µs | 11.7ms | BEGIN@25 | constant::
1 | 1 | 1 | 123µs | 123µs | BEGIN@36 | constant::
56 | 1 | 1 | 89µs | 89µs | CORE:match (opcode) | constant::
59 | 4 | 1 | 61µs | 61µs | CORE:regcomp (opcode) | constant::
1 | 1 | 1 | 12µs | 12µs | BEGIN@2 | constant::
1 | 1 | 1 | 10µs | 26µs | BEGIN@65 | constant::
1 | 1 | 1 | 9µs | 65µs | BEGIN@4 | constant::
1 | 1 | 1 | 8µs | 18µs | BEGIN@3 | constant::
1 | 1 | 1 | 7µs | 16µs | BEGIN@127 | constant::
1 | 1 | 1 | 6µs | 16µs | BEGIN@29 | constant::
3 | 3 | 1 | 6µs | 6µs | CORE:qr (opcode) | constant::
1 | 1 | 1 | 6µs | 29µs | BEGIN@6 | 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 | 35µs | 1 | 12µs | # spent 12µs within constant::BEGIN@2 which was called:
# once (12µs+0s) by Getopt::Long::BEGIN@215 at line 2 # spent 12µs making 1 call to constant::BEGIN@2 |
3 | 2 | 20µs | 2 | 29µs | # spent 18µs (8+10) within constant::BEGIN@3 which was called:
# once (8µs+10µs) by Getopt::Long::BEGIN@215 at line 3 # spent 18µs making 1 call to constant::BEGIN@3
# spent 10µs making 1 call to strict::import |
4 | 2 | 21µs | 2 | 122µs | # spent 65µs (9+57) within constant::BEGIN@4 which was called:
# once (9µs+57µs) by Getopt::Long::BEGIN@215 at line 4 # spent 65µs making 1 call to constant::BEGIN@4
# spent 56µs making 1 call to warnings::register::import |
5 | |||||
6 | 2 | 83µs | 2 | 52µs | # spent 29µs (6+23) within constant::BEGIN@6 which was called:
# once (6µs+23µs) by Getopt::Long::BEGIN@215 at line 6 # spent 29µs making 1 call to constant::BEGIN@6
# spent 23µs making 1 call to vars::import |
7 | 1 | 500ns | $VERSION = '1.23'; | ||
8 | |||||
9 | #======================================================================= | ||||
10 | |||||
11 | # Some names are evil choices. | ||||
12 | 1 | 5µs | my %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD }; | ||
13 | 1 | 1µs | $keywords{UNITCHECK}++ if $] > 5.009; | ||
14 | |||||
15 | 1 | 5µs | my %forced_into_main = map +($_, 1), | ||
16 | qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG }; | ||||
17 | |||||
18 | 1 | 6µs | my %forbidden = (%keywords, %forced_into_main); | ||
19 | |||||
20 | 1 | 600ns | my $str_end = $] >= 5.006 ? "\\z" : "\\Z"; | ||
21 | 1 | 29µs | 2 | 19µs | my $normal_constant_name = qr/^_?[^\W_0-9]\w*$str_end/; # spent 14µs making 1 call to constant::CORE:regcomp
# spent 5µs making 1 call to constant::CORE:qr |
22 | 1 | 9µs | 2 | 5µs | my $tolerable = qr/^[A-Za-z_]\w*$str_end/; # spent 4µs making 1 call to constant::CORE:regcomp
# spent 1µs making 1 call to constant::CORE:qr |
23 | 1 | 8µs | 2 | 4µs | my $boolean = qr/^[01]?$str_end/; # spent 4µs making 1 call to constant::CORE:regcomp
# spent 600ns making 1 call to constant::CORE:qr |
24 | |||||
25 | # spent 11.7ms (165µs+11.5) within constant::BEGIN@25 which was called:
# once (165µs+11.5ms) by Getopt::Long::BEGIN@215 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 | 110µs | 2 | 25µs | # spent 16µs (6+9) within constant::BEGIN@29 which was called:
# once (6µs+9µs) by Getopt::Long::BEGIN@215 at line 29 # spent 16µs making 1 call to constant::BEGIN@29
# spent 9µs making 1 call to strict::unimport |
30 | 1 | 900ns | my $const = $] > 5.009002; | ||
31 | 1 | 4µ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 | 200ns | return unless $const; | ||
36 | 3 | 248µs | 1 | 3.18ms | # spent 123µs within constant::BEGIN@36 which was called:
# once (123µs+0s) by constant::BEGIN@25 at line 45 # spent 3.18ms making 1 call to utf8::AUTOLOAD |
37 | 1 | 8µs | if (exists ${__PACKAGE__."::"}{"\xc4\x80"}) { | ||
38 | delete ${__PACKAGE__."::"}{"\xc4\x80"}; | ||||
39 | *_DOWNGRADE = sub () {1}; | ||||
40 | } | ||||
41 | else { | ||||
42 | 1 | 2µs | delete ${__PACKAGE__."::"}{chr 256}; | ||
43 | 1 | 3µs | *_DOWNGRADE = sub () {0}; | ||
44 | } | ||||
45 | 1 | 97µs | 2 | 11.8ms | } # spent 11.7ms making 1 call to constant::BEGIN@25
# spent 123µs 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 1.15ms (944µs+202µs) within constant::import which was called 37 times, avg 31µs/call:
# once (166µs+40µs) by Data::DPath::Context::BEGIN@64 at line 64 of Data/DPath/Context.pm
# once (83µs+20µs) by Data::DPath::Path::BEGIN@27 at line 27 of Data/DPath/Path.pm
# once (50µs+11µs) by Data::DPath::Filters::BEGIN@15 at line 16 of Data/DPath/Filters.pm
# once (42µs+10µs) by Getopt::Long::BEGIN@215 at line 215 of Getopt/Long.pm
# once (34µs+7µs) by Sys::Info::Constants::BEGIN@24 at line 24 of Sys/Info/Constants.pm
# once (33µs+7µs) by Data::Dumper::BEGIN@270 at line 270 of Data/Dumper.pm
# once (23µs+5µs) by Getopt::Long::BEGIN@225 at line 225 of Getopt/Long.pm
# once (21µs+5µs) by Sys::Info::Base::BEGIN@9 at line 9 of Sys/Info/Base.pm
# once (22µs+2µs) by Sys::Info::Constants::BEGIN@36 at line 36 of Sys/Info/Constants.pm
# once (20µs+4µs) by Sys::Info::Constants::BEGIN@32 at line 32 of Sys/Info/Constants.pm
# once (19µs+4µs) by Sys::Info::Constants::BEGIN@25 at line 25 of Sys/Info/Constants.pm
# once (18µs+4µs) by Getopt::Long::BEGIN@244 at line 244 of Getopt/Long.pm
# once (20µs+2µs) by Sys::Info::Constants::BEGIN@27 at line 27 of Sys/Info/Constants.pm
# once (18µs+4µs) by Sys::Info::Constants::BEGIN@26 at line 26 of Sys/Info/Constants.pm
# once (18µs+4µs) by Sys::Info::Base::BEGIN@12 at line 12 of Sys/Info/Base.pm
# once (18µs+4µs) by Sys::Info::Constants::BEGIN@30 at line 30 of Sys/Info/Constants.pm
# once (17µs+4µs) by Sys::Info::Constants::BEGIN@29 at line 29 of Sys/Info/Constants.pm
# once (17µs+4µs) by Getopt::Long::BEGIN@227 at line 227 of Getopt/Long.pm
# once (16µs+4µs) by Sys::Info::Constants::BEGIN@41 at line 41 of Sys/Info/Constants.pm
# once (16µs+4µs) by Sys::Info::Constants::BEGIN@37 at line 37 of Sys/Info/Constants.pm
# once (16µs+4µs) by Sys::Info::Constants::BEGIN@46 at line 46 of Sys/Info/Constants.pm
# once (16µs+4µs) by Sys::Info::Constants::BEGIN@44 at line 44 of Sys/Info/Constants.pm
# once (16µs+4µs) by Sys::Info::Constants::BEGIN@34 at line 34 of Sys/Info/Constants.pm
# once (16µs+4µs) by Sys::Info::Constants::BEGIN@35 at line 35 of Sys/Info/Constants.pm
# once (16µs+3µs) by Sys::Info::Constants::BEGIN@42 at line 42 of Sys/Info/Constants.pm
# once (16µs+4µs) by Getopt::Long::BEGIN@254 at line 254 of Getopt/Long.pm
# once (16µs+3µs) by Getopt::Long::BEGIN@229 at line 229 of Getopt/Long.pm
# once (17µs+2µs) by Sys::Info::Constants::BEGIN@39 at line 39 of Sys/Info/Constants.pm
# once (16µs+4µs) by Getopt::Long::BEGIN@231 at line 231 of Getopt/Long.pm
# once (16µs+3µs) by Getopt::Long::BEGIN@233 at line 233 of Getopt/Long.pm
# once (16µs+3µs) by Getopt::Long::BEGIN@230 at line 230 of Getopt/Long.pm
# once (16µs+3µs) by Sys::Info::Constants::BEGIN@48 at line 48 of Sys/Info/Constants.pm
# once (16µs+3µs) by Getopt::Long::BEGIN@235 at line 235 of Getopt/Long.pm
# once (16µs+3µs) by Getopt::Long::BEGIN@243 at line 243 of Getopt/Long.pm
# once (15µs+3µs) by Getopt::Long::BEGIN@232 at line 232 of Getopt/Long.pm
# once (16µs+3µs) by Getopt::Long::BEGIN@236 at line 236 of Getopt/Long.pm
# once (16µs+2µs) by Sys::Info::Constants::BEGIN@40 at line 40 of Sys/Info/Constants.pm | ||||
56 | 37 | 14µs | my $class = shift; | ||
57 | 37 | 9µs | return unless @_; # Ignore 'use constant;' | ||
58 | 37 | 4µs | my $constants; | ||
59 | 37 | 12µs | my $multiple = ref $_[0]; | ||
60 | 37 | 17µs | my $pkg = caller; | ||
61 | 37 | 4µs | my $flush_mro; | ||
62 | 37 | 3µs | my $symtab; | ||
63 | |||||
64 | 37 | 13µs | if (_CAN_PCS) { | ||
65 | 2 | 195µs | 2 | 42µs | # spent 26µs (10+16) within constant::BEGIN@65 which was called:
# once (10µs+16µs) by Getopt::Long::BEGIN@215 at line 65 # spent 26µs making 1 call to constant::BEGIN@65
# spent 16µs making 1 call to strict::unimport |
66 | 37 | 41µs | $symtab = \%{$pkg . '::'}; | ||
67 | }; | ||||
68 | |||||
69 | 37 | 9µs | if ( $multiple ) { | ||
70 | 3 | 3µs | if (ref $_[0] ne 'HASH') { | ||
71 | require Carp; | ||||
72 | Carp::croak("Invalid reference type '".ref(shift)."' not 'HASH'"); | ||||
73 | } | ||||
74 | 3 | 2µs | $constants = shift; | ||
75 | } else { | ||||
76 | 34 | 7µs | unless (defined $_[0]) { | ||
77 | require Carp; | ||||
78 | Carp::croak("Can't use undef as constant name"); | ||||
79 | } | ||||
80 | 34 | 31µs | $constants->{+shift} = undef; | ||
81 | } | ||||
82 | |||||
83 | 37 | 49µs | foreach my $name ( keys %$constants ) { | ||
84 | # Normal constant name | ||||
85 | 56 | 347µs | 112 | 129µs | if ($name =~ $normal_constant_name and !$forbidden{$name}) { # spent 89µs making 56 calls to constant::CORE:match, avg 2µs/call
# spent 40µs making 56 calls to constant::CORE:regcomp, avg 705ns/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 | 58 | 225µs | 2 | 25µs | # spent 16µs (7+9) within constant::BEGIN@127 which was called:
# once (7µs+9µs) by Getopt::Long::BEGIN@215 at line 127 # spent 16µs making 1 call to constant::BEGIN@127
# spent 9µs making 1 call to strict::unimport |
128 | 56 | 35µs | my $full_name = "${pkg}::$name"; | ||
129 | 56 | 54µs | $declared{$full_name}++; | ||
130 | 56 | 31µs | if ($multiple || @_ == 1) { | ||
131 | 52 | 24µ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 | 52 | 36µ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 | 52 | 143µs | 52 | 38µs | Internals::SvREADONLY($scalar, 1); # spent 38µs making 52 calls to Internals::SvREADONLY, avg 733ns/call |
148 | 52 | 35µs | $symtab->{$name} = \$scalar; | ||
149 | 52 | 15µs | ++$flush_mro; | ||
150 | } else { | ||||
151 | *$full_name = sub () { $scalar }; | ||||
152 | } | ||||
153 | } elsif (@_) { | ||||
154 | 4 | 9µs | my @list = @_; | ||
155 | 4 | 15µs | *$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 | 37 | 215µs | 33 | 35µs | mro::method_changed_in($pkg) if _CAN_PCS && $flush_mro; # spent 35µs making 33 calls to mro::method_changed_in, avg 1µs/call |
163 | } | ||||
164 | |||||
165 | 1 | 8µs | 1; | ||
166 | |||||
167 | __END__ | ||||
# spent 89µs within constant::CORE:match which was called 56 times, avg 2µs/call:
# 56 times (89µs+0s) by constant::import at line 85, avg 2µs/call | |||||
sub constant::CORE:qr; # opcode | |||||
# spent 61µs within constant::CORE:regcomp which was called 59 times, avg 1µs/call:
# 56 times (40µs+0s) by constant::import at line 85, avg 705ns/call
# once (14µs+0s) by Getopt::Long::BEGIN@215 at line 21
# once (4µs+0s) by Getopt::Long::BEGIN@215 at line 22
# once (4µs+0s) by Getopt::Long::BEGIN@215 at line 23 |