← Index
NYTProf Performance Profile   « line view »
For split.pl
  Run on Thu Apr 20 02:05:47 2023
Reported on Thu Apr 20 18:31:09 2023

Filename/usr/lib/x86_64-linux-gnu/perl-base/base.pm
StatementsExecuted 123 statements in 917µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
33370µs99µsbase::::import base::import
31112µs17µsbase::::__ANON__[:75] base::__ANON__[:75]
11110µs10µsYAML::XS::::BEGIN@1 YAML::XS::BEGIN@1
3115µs5µsbase::::has_fields base::has_fields
1114µs6µsbase::::BEGIN@4 base::BEGIN@4
3113µs3µsbase::::has_attr base::has_attr
3112µs2µsbase::::CORE:subst base::CORE:subst (opcode)
311700ns700nsbase::::CORE:match base::CORE:match (opcode)
0000s0sbase::::__ANON__[:131] base::__ANON__[:131]
0000s0sbase::::__ANON__[:132] base::__ANON__[:132]
0000s0sbase::::__ANON__[:52] base::__ANON__[:52]
0000s0sbase::::__ANON__[:59] base::__ANON__[:59]
0000s0sbase::::__ANON__[:67] base::__ANON__[:67]
0000s0sbase::__inc::scope_guard::::DESTROYbase::__inc::scope_guard::DESTROY
0000s0sbase::__inc::::unhook base::__inc::unhook
0000s0sbase::::get_attr base::get_attr
0000s0sbase::::inherit_fields base::inherit_fields
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1230µs110µs
# spent 10µs within YAML::XS::BEGIN@1 which was called: # once (10µs+0s) by YAML::XS::BEGIN@6 at line 1
use 5.008;
# spent 10µs making 1 call to YAML::XS::BEGIN@1
2package base;
3
42777µs29µs
# spent 6µs (4+3) within base::BEGIN@4 which was called: # once (4µs+3µs) by YAML::XS::BEGIN@6 at line 4
use strict 'vars';
# spent 6µs making 1 call to base::BEGIN@4 # spent 3µs making 1 call to strict::import
51300nsour $VERSION = '2.27';
611µs$VERSION =~ tr/_//d;
7
8# simplest way to avoid indexing of the package: no package statement
9sub base::__inc::unhook { @INC = grep !(ref eq 'CODE' && $_ == $_[0]), @INC }
10# instance is blessed array of coderefs to be removed from @INC at scope exit
11sub base::__inc::scope_guard::DESTROY { base::__inc::unhook $_ for @{$_[0]} }
12
13# constant.pm is slow
14sub SUCCESS () { 1 }
15
16sub PUBLIC () { 2**0 }
17sub PRIVATE () { 2**1 }
18sub INHERITED () { 2**2 }
19sub PROTECTED () { 2**3 }
20
211500nsmy $Fattr = \%fields::attr;
22
23
# spent 5µs within base::has_fields which was called 3 times, avg 2µs/call: # 3 times (5µs+0s) by base::import at line 175, avg 2µs/call
sub has_fields {
243900ns my($base) = shift;
2532µs my $fglob = ${"$base\::"}{FIELDS};
2633µs return( ($fglob && 'GLOB' eq ref($fglob) && *$fglob{HASH}) ? 1 : 0 );
27}
28
29
# spent 3µs within base::has_attr which was called 3 times, avg 1µs/call: # 3 times (3µs+0s) by base::import at line 175, avg 1µs/call
sub has_attr {
303500ns my($proto) = shift;
313700ns my($class) = ref $proto || $proto;
3233µs return exists $Fattr->{$class};
33}
34
35sub get_attr {
36 $Fattr->{$_[0]} = [1] unless $Fattr->{$_[0]};
37 return $Fattr->{$_[0]};
38}
39
401500nsif ($] < 5.009) {
41 *get_fields = sub {
42 # Shut up a possible typo warning.
43 () = \%{$_[0].'::FIELDS'};
44 my $f = \%{$_[0].'::FIELDS'};
45
46 # should be centralized in fields? perhaps
47 # fields::mk_FIELDS_be_OK. Peh. As long as %{ $package . '::FIELDS' }
48 # is used here anyway, it doesn't matter.
49 bless $f, 'pseudohash' if (ref($f) ne 'pseudohash');
50
51 return $f;
52 }
53}
54else {
55 *get_fields = sub {
56 # Shut up a possible typo warning.
57 () = \%{$_[0].'::FIELDS'};
58 return \%{$_[0].'::FIELDS'};
59 }
6012µs}
61
621200nsif ($] < 5.008) {
63 *_module_to_filename = sub {
64 (my $fn = $_[0]) =~ s!::!/!g;
65 $fn .= '.pm';
66 return $fn;
67 }
68}
69else {
70
# spent 17µs (12+4) within base::__ANON__[/usr/lib/x86_64-linux-gnu/perl-base/base.pm:75] which was called 3 times, avg 6µs/call: # 3 times (12µs+4µs) by base::import at line 101, avg 6µs/call
*_module_to_filename = sub {
7137µs32µs (my $fn = $_[0]) =~ s!::!/!g;
# spent 2µs making 3 calls to base::CORE:subst, avg 833ns/call
723900ns $fn .= '.pm';
7335µs32µs utf8::encode($fn);
# spent 2µs making 3 calls to utf8::encode, avg 600ns/call
7434µs return $fn;
75 }
761800ns}
77
78
# spent 99µs (70+29) within base::import which was called 3 times, avg 33µs/call: # once (28µs+13µs) by ExtUtils::MakeMaker::Locale::BEGIN@8 at line 8 of ExtUtils/MakeMaker/Locale.pm # once (25µs+10µs) by YAML::XS::BEGIN@6 at line 6 of YAML/XS.pm # once (18µs+7µs) by YAML::XS::LibYAML::BEGIN@8 at line 8 of YAML/XS/LibYAML.pm
sub import {
7931µs my $class = shift;
80
813600ns return SUCCESS unless @_;
82
83 # List of base classes from which we will inherit %FIELDS.
843400ns my $fields_base;
85
8631µs my $inheritor = caller(0);
87
883400ns my @bases;
8931µs foreach my $base (@_) {
903700ns if ( $inheritor eq $base ) {
91 warn "Class '$inheritor' tried to inherit from itself\n";
92 }
93
94319µs33µs next if grep $_->isa($base), ($inheritor, @bases);
# spent 3µs making 3 calls to UNIVERSAL::isa, avg 1µs/call
95
96 # Following blocks help isolate $SIG{__DIE__} and @INC changes
97 {
986800ns my $sigdie;
99 {
10064µs local $SIG{__DIE__};
10134µs317µs my $fn = _module_to_filename($base);
# spent 17µs making 3 calls to base::__ANON__[base.pm:75], avg 6µs/call
1023200ns my $dot_hidden;
1033700ns eval {
1043200ns my $guard;
1053700ns if ($INC[-1] eq '.' && %{"$base\::"}) {
106 # So: the package already exists => this an optional load
107 # And: there is a dot at the end of @INC => we want to hide it
108 # However: we only want to hide it during our *own* require()
109 # (i.e. without affecting nested require()s).
110 # So we add a hook to @INC whose job is to hide the dot, but which
111 # first checks checks the callstack depth, because within nested
112 # require()s the callstack is deeper.
113 # Since CORE::GLOBAL::require makes it unknowable in advance what
114 # the exact relevant callstack depth will be, we have to record it
115 # inside a hook. So we put another hook just for that at the front
116 # of @INC, where it's guaranteed to run -- immediately.
117 # The dot-hiding hook does its job by sitting directly in front of
118 # the dot and removing itself from @INC when reached. This causes
119 # the dot to move up one index in @INC, causing the loop inside
120 # pp_require() to skip it.
121 # Loaded coded may disturb this precise arrangement, but that's OK
122 # because the hook is inert by that time. It is only active during
123 # the top-level require(), when @INC is in our control. The only
124 # possible gotcha is if other hooks already in @INC modify @INC in
125 # some way during that initial require().
126 # Note that this jiggery hookery works just fine recursively: if
127 # a module loaded via base.pm uses base.pm itself, there will be
128 # one pair of hooks in @INC per base::import call frame, but the
129 # pairs from different nestings do not interfere with each other.
130 my $lvl;
131 unshift @INC, sub { return if defined $lvl; 1 while defined caller ++$lvl; () };
132 splice @INC, -1, 0, sub { return if defined caller $lvl; ++$dot_hidden, &base::__inc::unhook; () };
133 $guard = bless [ @INC[0,-2] ], 'base::__inc::scope_guard';
134 }
13531µs require $fn
136 };
1373400ns if ($dot_hidden && (my @fn = grep -e && !( -d _ || -b _ ), $fn.'c', $fn)) {
138 require Carp;
139 Carp::croak(<<ERROR);
140Base class package "$base" is not empty but "$fn[0]" exists in the current directory.
141 To help avoid security issues, base.pm now refuses to load optional modules
142 from the current working directory when it is the last entry in \@INC.
143 If your software worked on previous versions of Perl, the best solution
144 is to use FindBin to detect the path properly and to add that path to
145 \@INC. As a last resort, you can re-enable looking in the current working
146 directory by adding "use lib '.'" to your code.
147ERROR
148 }
149 # Only ignore "Can't locate" errors from our eval require.
150 # Other fatal errors (syntax etc) must be reported.
151 #
152 # changing the check here is fragile - if the check
153 # here isn't catching every error you want, you should
154 # probably be using parent.pm, which doesn't try to
155 # guess whether require is needed or failed,
156 # see [perl #118561]
15735µs3700ns die if $@ && $@ !~ /^Can't locate \Q$fn\E .*? at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/s
# spent 700ns making 3 calls to base::CORE:match, avg 233ns/call
158 || $@ =~ /Compilation failed in require at .* line [0-9]+(?:, <[^>]*> (?:line|chunk) [0-9]+)?\.\n\z/;
15932µs unless (%{"$base\::"}) {
160 require Carp;
161 local $" = " ";
162 Carp::croak(<<ERROR);
163Base class package "$base" is empty.
164 (Perhaps you need to 'use' the module which defines that package first,
165 or make that module available in \@INC (\@INC contains: @INC).
166ERROR
167 }
16835µs $sigdie = $SIG{__DIE__} || undef;
169 }
170 # Make sure a global $SIG{__DIE__} makes it out of the localization.
1713800ns $SIG{__DIE__} = $sigdie if defined $sigdie;
172 }
17331µs push @bases, $base;
174
17535µs69µs if ( has_fields($base) || has_attr($base) ) {
# spent 5µs making 3 calls to base::has_fields, avg 2µs/call # spent 3µs making 3 calls to base::has_attr, avg 1µs/call
176 # No multiple fields inheritance *suck*
177 if ($fields_base) {
178 require Carp;
179 Carp::croak("Can't multiply inherit fields");
180 } else {
181 $fields_base = $base;
182 }
183 }
184 }
185 # Save this until the end so it's all or nothing if the above loop croaks.
186315µs push @{"$inheritor\::ISA"}, @bases;
187
18835µs if( defined $fields_base ) {
189 inherit_fields($inheritor, $fields_base);
190 }
191}
192
193sub inherit_fields {
194 my($derived, $base) = @_;
195
196 return SUCCESS unless $base;
197
198 my $battr = get_attr($base);
199 my $dattr = get_attr($derived);
200 my $dfields = get_fields($derived);
201 my $bfields = get_fields($base);
202
203 $dattr->[0] = @$battr;
204
205 if( keys %$dfields ) {
206 warn <<"END";
207$derived is inheriting from $base but already has its own fields!
208This will cause problems. Be sure you use base BEFORE declaring fields.
209END
210
211 }
212
213 # Iterate through the base's fields adding all the non-private
214 # ones to the derived class. Hang on to the original attribute
215 # (Public, Private, etc...) and add Inherited.
216 # This is all too complicated to do efficiently with add_fields().
217 while (my($k,$v) = each %$bfields) {
218 my $fno;
219 if ($fno = $dfields->{$k} and $fno != $v) {
220 require Carp;
221 Carp::croak ("Inherited fields can't override existing fields");
222 }
223
224 if( $battr->[$v] & PRIVATE ) {
225 $dattr->[$v] = PRIVATE | INHERITED;
226 }
227 else {
228 $dattr->[$v] = INHERITED | $battr->[$v];
229 $dfields->{$k} = $v;
230 }
231 }
232
233 foreach my $idx (1..$#{$battr}) {
234 next if defined $dattr->[$idx];
235 $dattr->[$idx] = $battr->[$idx] & INHERITED;
236 }
237}
238
23914µs1;
240
241__END__
 
# spent 700ns within base::CORE:match which was called 3 times, avg 233ns/call: # 3 times (700ns+0s) by base::import at line 157, avg 233ns/call
sub base::CORE:match; # opcode
# spent 2µs within base::CORE:subst which was called 3 times, avg 833ns/call: # 3 times (2µs+0s) by base::__ANON__[/usr/lib/x86_64-linux-gnu/perl-base/base.pm:75] at line 71, avg 833ns/call
sub base::CORE:subst; # opcode