| Filename | /usr/libdata/perl5/constant.pm |
| Statements | Executed 2938 statements in 39.6ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 83 | 83 | 7 | 4.98ms | 6.47ms | constant::import |
| 109 | 1 | 1 | 778µs | 778µs | constant::CORE:regcomp (opcode) |
| 1 | 1 | 1 | 647µs | 916µs | constant::BEGIN@4 |
| 109 | 1 | 1 | 235µs | 235µs | constant::CORE:subst (opcode) |
| 109 | 1 | 1 | 211µs | 211µs | constant::CORE:match (opcode) |
| 3 | 3 | 1 | 64µs | 64µs | constant::CORE:qr (opcode) |
| 1 | 1 | 1 | 58µs | 62µs | constant::BEGIN@24 |
| 1 | 1 | 1 | 46µs | 46µs | constant::BEGIN@2 |
| 1 | 1 | 1 | 18µs | 52µs | constant::BEGIN@65 |
| 1 | 1 | 1 | 18µs | 26µs | constant::BEGIN@3 |
| 1 | 1 | 1 | 15µs | 45µs | constant::BEGIN@40 |
| 1 | 1 | 1 | 14µs | 36µs | constant::BEGIN@141 |
| 1 | 1 | 1 | 13µs | 34µs | constant::BEGIN@90 |
| 0 | 0 | 0 | 0s | 0s | constant::__ANON__[:174] |
| 0 | 0 | 0 | 0s | 0s | constant::__ANON__[:190] |
| 0 | 0 | 0 | 0s | 0s | constant::__ANON__[:192] |
| 0 | 0 | 0 | 0s | 0s | constant::__ANON__[:41] |
| 0 | 0 | 0 | 0s | 0s | constant::__ANON__[:42] |
| 0 | 0 | 0 | 0s | 0s | constant::__ANON__[:43] |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package constant; | ||||
| 2 | 2 | 85µs | 1 | 46µs | # spent 46µs within constant::BEGIN@2 which was called:
# once (46µs+0s) by OpenBSD::PackageInfo::BEGIN@31 at line 2 # spent 46µs making 1 call to constant::BEGIN@2 |
| 3 | 2 | 42µs | 2 | 35µs | # spent 26µs (18+9) within constant::BEGIN@3 which was called:
# once (18µs+9µs) by OpenBSD::PackageInfo::BEGIN@31 at line 3 # spent 26µs making 1 call to constant::BEGIN@3
# spent 9µs making 1 call to strict::import |
| 4 | 2 | 1.31ms | 2 | 1.18ms | # spent 916µs (647+269) within constant::BEGIN@4 which was called:
# once (647µs+269µs) by OpenBSD::PackageInfo::BEGIN@31 at line 4 # spent 916µs making 1 call to constant::BEGIN@4
# spent 269µs making 1 call to warnings::register::import |
| 5 | |||||
| 6 | 1 | 1µs | our $VERSION = '1.33'; | ||
| 7 | our %declared; | ||||
| 8 | |||||
| 9 | #======================================================================= | ||||
| 10 | |||||
| 11 | # Some names are evil choices. | ||||
| 12 | 1 | 220µs | my %keywords = map +($_, 1), qw{ BEGIN INIT CHECK END DESTROY AUTOLOAD }; | ||
| 13 | 1 | 2µs | $keywords{UNITCHECK}++ if $] > 5.009; | ||
| 14 | |||||
| 15 | 1 | 7µs | my %forced_into_main = map +($_, 1), | ||
| 16 | qw{ STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG }; | ||||
| 17 | |||||
| 18 | 1 | 51µs | my %forbidden = (%keywords, %forced_into_main); | ||
| 19 | |||||
| 20 | 1 | 69µs | 1 | 60µs | my $normal_constant_name = qr/^_?[^\W_0-9]\w*\z/; # spent 60µs making 1 call to constant::CORE:qr |
| 21 | 1 | 6µs | 1 | 3µs | my $tolerable = qr/^[A-Za-z_]\w*\z/; # spent 3µs making 1 call to constant::CORE:qr |
| 22 | 1 | 5µs | 1 | 2µs | my $boolean = qr/^[01]?\z/; # spent 2µs making 1 call to constant::CORE:qr |
| 23 | |||||
| 24 | # spent 62µs (58+4) within constant::BEGIN@24 which was called:
# once (58µs+4µs) by OpenBSD::PackageInfo::BEGIN@31 at line 45 | ||||
| 25 | # We'd like to do use constant _CAN_PCS => $] > 5.009002 | ||||
| 26 | # but that's a bit tricky before we load the constant module :-) | ||||
| 27 | # By doing this, we save several run time checks for *every* call | ||||
| 28 | # to import. | ||||
| 29 | 1 | 4µs | my $const = $] > 5.009002; | ||
| 30 | 1 | 2µs | my $downgrade = $] < 5.015004; # && $] >= 5.008 | ||
| 31 | 1 | 2µs | my $constarray = exists &_make_const; | ||
| 32 | 1 | 10µs | if ($const) { | ||
| 33 | 1 | 23µs | 1 | 3µs | Internals::SvREADONLY($const, 1); # spent 3µs making 1 call to Internals::SvREADONLY |
| 34 | 1 | 6µs | 1 | 1µs | Internals::SvREADONLY($downgrade, 1); # spent 1µs making 1 call to Internals::SvREADONLY |
| 35 | 1 | 4µs | $constant::{_CAN_PCS} = \$const; | ||
| 36 | 1 | 900ns | $constant::{_DOWNGRADE} = \$downgrade; | ||
| 37 | 1 | 2µs | $constant::{_CAN_PCS_FOR_ARRAY} = \$constarray; | ||
| 38 | } | ||||
| 39 | else { | ||||
| 40 | 2 | 28.6ms | 2 | 74µs | # spent 45µs (15+30) within constant::BEGIN@40 which was called:
# once (15µs+30µs) by OpenBSD::PackageInfo::BEGIN@31 at line 40 # spent 45µs making 1 call to constant::BEGIN@40
# spent 30µs making 1 call to strict::unimport |
| 41 | *{"_CAN_PCS"} = sub () {$const}; | ||||
| 42 | *{"_DOWNGRADE"} = sub () { $downgrade }; | ||||
| 43 | *{"_CAN_PCS_FOR_ARRAY"} = sub () { $constarray }; | ||||
| 44 | } | ||||
| 45 | 1 | 164µs | 1 | 62µs | } # spent 62µs making 1 call to constant::BEGIN@24 |
| 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 6.47ms (4.98+1.49) within constant::import which was called 83 times, avg 78µs/call:
# once (200µs+432µs) by Compress::Raw::Zlib::BEGIN@105 at line 105 of Compress/Raw/Zlib.pm
# once (443µs+99µs) by OpenBSD::Ustar::BEGIN@25 at line 46 of OpenBSD/Ustar.pm
# once (212µs+209µs) by OpenBSD::PackageInfo::BEGIN@31 at line 37 of OpenBSD/PackageInfo.pm
# once (123µs+26µs) by OpenBSD::CompactWriter::BEGIN@738 at line 743 of OpenBSD/Ustar.pm
# once (84µs+22µs) by IO::Compress::Base::Common::BEGIN@45 at line 45 of IO/Compress/Base/Common.pm
# once (82µs+18µs) by Compress::Raw::Zlib::BEGIN@136 at line 136 of Compress/Raw/Zlib.pm
# once (84µs+14µs) by Compress::Raw::Zlib::BEGIN@118 at line 118 of Compress/Raw/Zlib.pm
# once (80µs+16µs) by IO::Compress::Base::Common::BEGIN@51 at line 51 of IO/Compress/Base/Common.pm
# once (78µs+12µs) by Compress::Raw::Zlib::BEGIN@119 at line 119 of Compress/Raw/Zlib.pm
# once (72µs+12µs) by Compress::Raw::Zlib::BEGIN@137 at line 137 of Compress/Raw/Zlib.pm
# once (70µs+13µs) by Compress::Raw::Zlib::BEGIN@106 at line 106 of Compress/Raw/Zlib.pm
# once (70µs+11µs) by Compress::Raw::Zlib::BEGIN@139 at line 139 of Compress/Raw/Zlib.pm
# once (62µs+19µs) by File::Spec::Unix::BEGIN@130 at line 130 of File/Spec/Unix.pm
# once (65µs+12µs) by IO::Compress::Base::Common::BEGIN@46 at line 46 of IO/Compress/Base/Common.pm
# once (62µs+14µs) by IO::Compress::Base::Common::BEGIN@148 at line 148 of IO/Compress/Base/Common.pm
# once (62µs+12µs) by Compress::Raw::Zlib::BEGIN@120 at line 120 of Compress/Raw/Zlib.pm
# once (64µs+10µs) by Compress::Raw::Zlib::BEGIN@145 at line 145 of Compress/Raw/Zlib.pm
# once (62µs+12µs) by Compress::Raw::Zlib::BEGIN@138 at line 138 of Compress/Raw/Zlib.pm
# once (62µs+12µs) by Compress::Raw::Zlib::BEGIN@121 at line 121 of Compress/Raw/Zlib.pm
# once (62µs+10µs) by Compress::Raw::Zlib::BEGIN@148 at line 148 of Compress/Raw/Zlib.pm
# once (62µs+10µs) by IO::Compress::Base::Common::BEGIN@47 at line 47 of IO/Compress/Base/Common.pm
# once (62µs+11µs) by Compress::Raw::Zlib::BEGIN@146 at line 146 of Compress/Raw/Zlib.pm
# once (62µs+10µs) by IO::Compress::Base::Common::BEGIN@49 at line 49 of IO/Compress/Base/Common.pm
# once (60µs+10µs) by IO::Compress::Base::Common::BEGIN@50 at line 50 of IO/Compress/Base/Common.pm
# once (59µs+12µs) by Compress::Raw::Zlib::BEGIN@122 at line 122 of Compress/Raw/Zlib.pm
# once (60µs+11µs) by IO::Compress::Base::Common::BEGIN@48 at line 48 of IO/Compress/Base/Common.pm
# once (59µs+11µs) by Compress::Raw::Zlib::BEGIN@147 at line 147 of Compress/Raw/Zlib.pm
# once (51µs+18µs) by IO::Compress::Base::Common::BEGIN@480 at line 480 of IO/Compress/Base/Common.pm
# once (58µs+11µs) by IO::Compress::Gzip::Constants::BEGIN@65 at line 65 of IO/Compress/Gzip/Constants.pm
# once (60µs+8µs) by IO::Compress::Base::Common::BEGIN@149 at line 149 of IO/Compress/Base/Common.pm
# once (57µs+11µs) by Compress::Raw::Zlib::BEGIN@149 at line 149 of Compress/Raw/Zlib.pm
# once (57µs+10µs) by Compress::Raw::Zlib::BEGIN@150 at line 150 of Compress/Raw/Zlib.pm
# once (50µs+9µs) by IO::Uncompress::Base::BEGIN@14 at line 14 of IO/Uncompress/Base.pm
# once (49µs+9µs) by File::Spec::Unix::BEGIN@223 at line 223 of File/Spec/Unix.pm
# once (46µs+13µs) by IO::Compress::Base::Common::BEGIN@481 at line 481 of IO/Compress/Base/Common.pm
# once (47µs+9µs) by U64::BEGIN@835 at line 835 of IO/Compress/Base/Common.pm
# once (49µs+7µs) by IO::Compress::Base::Common::BEGIN@150 at line 150 of IO/Compress/Base/Common.pm
# once (49µs+7µs) by IO::Compress::Base::Common::BEGIN@485 at line 485 of IO/Compress/Base/Common.pm
# once (49µs+7µs) by IO::Compress::Base::Common::BEGIN@489 at line 489 of IO/Compress/Base/Common.pm
# once (48µs+8µs) by IO::Uncompress::Base::BEGIN@15 at line 15 of IO/Uncompress/Base.pm
# once (45µs+10µs) by IO::Compress::Gzip::Constants::BEGIN@75 at line 75 of IO/Compress/Gzip/Constants.pm
# once (46µs+9µs) by File::Spec::Unix::BEGIN@245 at line 245 of File/Spec/Unix.pm
# once (47µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@76 at line 76 of IO/Compress/Gzip/Constants.pm
# once (47µs+7µs) by IO::Compress::Base::Common::BEGIN@482 at line 482 of IO/Compress/Base/Common.pm
# once (46µs+8µs) by File::Spec::Unix::BEGIN@139 at line 139 of File/Spec/Unix.pm
# once (46µs+7µs) by IO::Compress::Base::Common::BEGIN@152 at line 152 of IO/Compress/Base/Common.pm
# once (47µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@113 at line 113 of IO/Compress/Gzip/Constants.pm
# once (42µs+10µs) by IO::Compress::Base::Common::BEGIN@490 at line 490 of IO/Compress/Base/Common.pm
# once (44µs+8µs) by File::Spec::Unix::BEGIN@148 at line 148 of File/Spec/Unix.pm
# once (41µs+10µs) by IO::Compress::Base::Common::BEGIN@495 at line 495 of IO/Compress/Base/Common.pm
# once (41µs+9µs) by IO::Compress::Base::Common::BEGIN@500 at line 500 of IO/Compress/Base/Common.pm
# once (43µs+7µs) by IO::Compress::Base::Common::BEGIN@483 at line 483 of IO/Compress/Base/Common.pm
# once (44µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@77 at line 77 of IO/Compress/Gzip/Constants.pm
# once (42µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@66 at line 66 of IO/Compress/Gzip/Constants.pm
# once (42µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@143 at line 145 of IO/Compress/Gzip/Constants.pm
# once (42µs+7µs) by U64::BEGIN@836 at line 836 of IO/Compress/Base/Common.pm
# once (42µs+7µs) by U64::BEGIN@837 at line 837 of IO/Compress/Base/Common.pm
# once (42µs+7µs) by IO::Compress::Base::Common::BEGIN@484 at line 484 of IO/Compress/Base/Common.pm
# once (41µs+7µs) by IO::Compress::Base::Common::BEGIN@499 at line 499 of IO/Compress/Base/Common.pm
# once (41µs+6µs) by IO::Compress::Base::Common::BEGIN@492 at line 492 of IO/Compress/Base/Common.pm
# once (39µs+9µs) by IO::Compress::Gzip::Constants::BEGIN@87 at line 87 of IO/Compress/Gzip/Constants.pm
# once (41µs+6µs) by IO::Compress::Base::Common::BEGIN@493 at line 493 of IO/Compress/Base/Common.pm
# once (41µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@115 at line 115 of IO/Compress/Gzip/Constants.pm
# once (42µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@84 at line 84 of IO/Compress/Gzip/Constants.pm
# once (41µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@109 at line 109 of IO/Compress/Gzip/Constants.pm
# once (41µs+6µs) by IO::Compress::Base::Common::BEGIN@494 at line 494 of IO/Compress/Base/Common.pm
# once (40µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@111 at line 111 of IO/Compress/Gzip/Constants.pm
# once (41µs+6µs) by U64::BEGIN@838 at line 838 of IO/Compress/Base/Common.pm
# once (41µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@67 at line 67 of IO/Compress/Gzip/Constants.pm
# once (40µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@80 at line 80 of IO/Compress/Gzip/Constants.pm
# once (40µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@70 at line 70 of IO/Compress/Gzip/Constants.pm
# once (40µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@86 at line 86 of IO/Compress/Gzip/Constants.pm
# once (40µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@114 at line 114 of IO/Compress/Gzip/Constants.pm
# once (39µs+7µs) by IO::Compress::Gzip::Constants::BEGIN@90 at line 91 of IO/Compress/Gzip/Constants.pm
# once (40µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@73 at line 73 of IO/Compress/Gzip/Constants.pm
# once (40µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@69 at line 69 of IO/Compress/Gzip/Constants.pm
# once (39µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@78 at line 78 of IO/Compress/Gzip/Constants.pm
# once (39µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@74 at line 74 of IO/Compress/Gzip/Constants.pm
# once (39µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@119 at line 119 of IO/Compress/Gzip/Constants.pm
# once (39µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@88 at line 88 of IO/Compress/Gzip/Constants.pm
# once (39µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@89 at line 89 of IO/Compress/Gzip/Constants.pm
# once (39µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@92 at line 93 of IO/Compress/Gzip/Constants.pm
# once (39µs+6µs) by IO::Compress::Gzip::Constants::BEGIN@82 at line 82 of IO/Compress/Gzip/Constants.pm | ||||
| 56 | 83 | 71µs | my $class = shift; | ||
| 57 | 83 | 65µs | return unless @_; # Ignore 'use constant;' | ||
| 58 | 83 | 54µs | my $constants; | ||
| 59 | 83 | 92µs | my $multiple = ref $_[0]; | ||
| 60 | 83 | 94µs | my $caller = caller; | ||
| 61 | 83 | 58µs | my $flush_mro; | ||
| 62 | my $symtab; | ||||
| 63 | |||||
| 64 | 83 | 114µs | if (_CAN_PCS) { | ||
| 65 | 2 | 200µs | 2 | 86µs | # spent 52µs (18+34) within constant::BEGIN@65 which was called:
# once (18µs+34µs) by OpenBSD::PackageInfo::BEGIN@31 at line 65 # spent 52µs making 1 call to constant::BEGIN@65
# spent 34µs making 1 call to strict::unimport |
| 66 | 83 | 141µs | $symtab = \%{$caller . '::'}; | ||
| 67 | }; | ||||
| 68 | |||||
| 69 | 83 | 112µs | if ( $multiple ) { | ||
| 70 | 3 | 4µ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 | 80 | 57µs | unless (defined $_[0]) { | ||
| 77 | require Carp; | ||||
| 78 | Carp::croak("Can't use undef as constant name"); | ||||
| 79 | } | ||||
| 80 | 80 | 193µs | $constants->{+shift} = undef; | ||
| 81 | } | ||||
| 82 | |||||
| 83 | 83 | 227µs | foreach my $name ( keys %$constants ) { | ||
| 84 | 109 | 68µs | my $pkg; | ||
| 85 | 109 | 82µs | my $symtab = $symtab; | ||
| 86 | 109 | 79µs | my $orig_name = $name; | ||
| 87 | 109 | 643µs | 109 | 235µs | if ($name =~ s/(.*)(?:::|')(?=.)//s) { # spent 235µs making 109 calls to constant::CORE:subst, avg 2µs/call |
| 88 | $pkg = $1; | ||||
| 89 | if (_CAN_PCS && $pkg ne $caller) { | ||||
| 90 | 2 | 399µs | 2 | 56µs | # spent 34µs (13+22) within constant::BEGIN@90 which was called:
# once (13µs+22µs) by OpenBSD::PackageInfo::BEGIN@31 at line 90 # spent 34µs making 1 call to constant::BEGIN@90
# spent 22µs making 1 call to strict::unimport |
| 91 | $symtab = \%{$pkg . '::'}; | ||||
| 92 | } | ||||
| 93 | } | ||||
| 94 | else { | ||||
| 95 | 109 | 76µs | $pkg = $caller; | ||
| 96 | } | ||||
| 97 | |||||
| 98 | # Normal constant name | ||||
| 99 | 109 | 1.49ms | 218 | 989µs | if ($name =~ $normal_constant_name and !$forbidden{$name}) { # spent 778µs making 109 calls to constant::CORE:regcomp, avg 7µs/call
# spent 211µs making 109 calls to constant::CORE:match, avg 2µs/call |
| 100 | # Everything is okay | ||||
| 101 | |||||
| 102 | # Name forced into main, but we're not in main. Fatal. | ||||
| 103 | } elsif ($forced_into_main{$name} and $pkg ne 'main') { | ||||
| 104 | require Carp; | ||||
| 105 | Carp::croak("Constant name '$name' is forced into main::"); | ||||
| 106 | |||||
| 107 | # Starts with double underscore. Fatal. | ||||
| 108 | } elsif ($name =~ /^__/) { | ||||
| 109 | require Carp; | ||||
| 110 | Carp::croak("Constant name '$name' begins with '__'"); | ||||
| 111 | |||||
| 112 | # Maybe the name is tolerable | ||||
| 113 | } elsif ($name =~ $tolerable) { | ||||
| 114 | # Then we'll warn only if you've asked for warnings | ||||
| 115 | if (warnings::enabled()) { | ||||
| 116 | if ($keywords{$name}) { | ||||
| 117 | warnings::warn("Constant name '$name' is a Perl keyword"); | ||||
| 118 | } elsif ($forced_into_main{$name}) { | ||||
| 119 | warnings::warn("Constant name '$name' is " . | ||||
| 120 | "forced into package main::"); | ||||
| 121 | } | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | # Looks like a boolean | ||||
| 125 | # use constant FRED == fred; | ||||
| 126 | } elsif ($name =~ $boolean) { | ||||
| 127 | require Carp; | ||||
| 128 | if (@_) { | ||||
| 129 | Carp::croak("Constant name '$name' is invalid"); | ||||
| 130 | } else { | ||||
| 131 | Carp::croak("Constant name looks like boolean value"); | ||||
| 132 | } | ||||
| 133 | |||||
| 134 | } else { | ||||
| 135 | # Must have bad characters | ||||
| 136 | require Carp; | ||||
| 137 | Carp::croak("Constant name '$name' has invalid characters"); | ||||
| 138 | } | ||||
| 139 | |||||
| 140 | { | ||||
| 141 | 111 | 1.92ms | 2 | 58µs | # spent 36µs (14+22) within constant::BEGIN@141 which was called:
# once (14µs+22µs) by OpenBSD::PackageInfo::BEGIN@31 at line 141 # spent 36µs making 1 call to constant::BEGIN@141
# spent 22µs making 1 call to strict::unimport |
| 142 | 109 | 119µs | my $full_name = "${pkg}::$name"; | ||
| 143 | 109 | 198µs | $declared{$full_name}++; | ||
| 144 | 109 | 161µs | if ($multiple || @_ == 1) { | ||
| 145 | 109 | 87µs | my $scalar = $multiple ? $constants->{$orig_name} : $_[0]; | ||
| 146 | |||||
| 147 | if (_DOWNGRADE) { # for 5.8 to 5.14 | ||||
| 148 | # Work around perl bug #31991: Sub names (actually glob | ||||
| 149 | # names in general) ignore the UTF8 flag. So we have to | ||||
| 150 | # turn it off to get the "right" symbol table entry. | ||||
| 151 | utf8::is_utf8 $name and utf8::encode $name; | ||||
| 152 | } | ||||
| 153 | |||||
| 154 | # The constant serves to optimise this entire block out on | ||||
| 155 | # 5.8 and earlier. | ||||
| 156 | 109 | 141µs | if (_CAN_PCS) { | ||
| 157 | # Use a reference as a proxy for a constant subroutine. | ||||
| 158 | # If this is not a glob yet, it saves space. If it is | ||||
| 159 | # a glob, we must still create it this way to get the | ||||
| 160 | # right internal flags set, as constants are distinct | ||||
| 161 | # from subroutines created with sub(){...}. | ||||
| 162 | # The check in Perl_ck_rvconst knows that inlinable | ||||
| 163 | # constants from cv_const_sv are read only. So we have to: | ||||
| 164 | 109 | 470µs | 109 | 144µs | Internals::SvREADONLY($scalar, 1); # spent 144µs making 109 calls to Internals::SvREADONLY, avg 1µs/call |
| 165 | 109 | 171µs | if (!exists $symtab->{$name}) { | ||
| 166 | 109 | 124µs | $symtab->{$name} = \$scalar; | ||
| 167 | 109 | 116µs | ++$flush_mro->{$pkg}; | ||
| 168 | } | ||||
| 169 | else { | ||||
| 170 | local $constant::{_dummy} = \$scalar; | ||||
| 171 | *$full_name = \&{"_dummy"}; | ||||
| 172 | } | ||||
| 173 | } else { | ||||
| 174 | *$full_name = sub () { $scalar }; | ||||
| 175 | } | ||||
| 176 | } elsif (@_) { | ||||
| 177 | my @list = @_; | ||||
| 178 | if (_CAN_PCS_FOR_ARRAY) { | ||||
| 179 | _make_const($list[$_]) for 0..$#list; | ||||
| 180 | _make_const(@list); | ||||
| 181 | if (!exists $symtab->{$name}) { | ||||
| 182 | $symtab->{$name} = \@list; | ||||
| 183 | $flush_mro->{$pkg}++; | ||||
| 184 | } | ||||
| 185 | else { | ||||
| 186 | local $constant::{_dummy} = \@list; | ||||
| 187 | *$full_name = \&{"_dummy"}; | ||||
| 188 | } | ||||
| 189 | } | ||||
| 190 | else { *$full_name = sub () { @list }; } | ||||
| 191 | } else { | ||||
| 192 | *$full_name = sub () { }; | ||||
| 193 | } | ||||
| 194 | } | ||||
| 195 | } | ||||
| 196 | # Flush the cache exactly once if we make any direct symbol table changes. | ||||
| 197 | 83 | 633µs | if (_CAN_PCS && $flush_mro) { | ||
| 198 | 83 | 556µs | 83 | 120µs | mro::method_changed_in($_) for keys %$flush_mro; # spent 120µs making 83 calls to mro::method_changed_in, avg 1µs/call |
| 199 | } | ||||
| 200 | } | ||||
| 201 | |||||
| 202 | 1 | 18µs | 1; | ||
| 203 | |||||
| 204 | __END__ | ||||
# spent 211µs within constant::CORE:match which was called 109 times, avg 2µs/call:
# 109 times (211µs+0s) by constant::import at line 99, avg 2µs/call | |||||
sub constant::CORE:qr; # opcode | |||||
# spent 778µs within constant::CORE:regcomp which was called 109 times, avg 7µs/call:
# 109 times (778µs+0s) by constant::import at line 99, avg 7µs/call | |||||
# spent 235µs within constant::CORE:subst which was called 109 times, avg 2µs/call:
# 109 times (235µs+0s) by constant::import at line 87, avg 2µs/call |