← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 16:10:05 2022
Reported on Wed Dec 14 16:12:58 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/ArrayRef.pm
StatementsExecuted 282 statements in 1.63ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2411496µs3.23msTypes::Standard::ArrayRef::::__ANON__[:121]Types::Standard::ArrayRef::__ANON__[:121]
41195µs2.66msTypes::Standard::ArrayRef::::__constraint_generatorTypes::Standard::ArrayRef::__constraint_generator
41140µs86µsTypes::Standard::ArrayRef::::__inline_generatorTypes::Standard::ArrayRef::__inline_generator
11132µs32µsTypes::Standard::ArrayRef::::BEGIN@5Types::Standard::ArrayRef::BEGIN@5
11110µs13µsTypes::Standard::ArrayRef::::BEGIN@6Types::Standard::ArrayRef::BEGIN@6
1118µs27µsTypes::Standard::ArrayRef::::BEGIN@22Types::Standard::ArrayRef::BEGIN@22
1118µs41µsTypes::Standard::ArrayRef::::BEGIN@7Types::Standard::ArrayRef::BEGIN@7
1113µs3µsTypes::Standard::ArrayRef::::BEGIN@16Types::Standard::ArrayRef::BEGIN@16
1113µs3µsTypes::Standard::ArrayRef::::BEGIN@18Types::Standard::ArrayRef::BEGIN@18
1113µs3µsTypes::Standard::ArrayRef::::BEGIN@9Types::Standard::ArrayRef::BEGIN@9
1112µs2µsTypes::Standard::ArrayRef::::BEGIN@17Types::Standard::ArrayRef::BEGIN@17
0000s0sTypes::Standard::ArrayRef::::__ANON__[:186]Types::Standard::ArrayRef::__ANON__[:186]
0000s0sTypes::Standard::ArrayRef::::__ANON__[:199]Types::Standard::ArrayRef::__ANON__[:199]
0000s0sTypes::Standard::ArrayRef::::__ANON__[:58]Types::Standard::ArrayRef::__ANON__[:58]
0000s0sTypes::Standard::ArrayRef::::__ANON__[:67]Types::Standard::ArrayRef::__ANON__[:67]
0000s0sTypes::Standard::ArrayRef::::__ANON__[:75]Types::Standard::ArrayRef::__ANON__[:75]
0000s0sTypes::Standard::ArrayRef::::__ANON__[:84]Types::Standard::ArrayRef::__ANON__[:84]
0000s0sTypes::Standard::ArrayRef::::__coercion_generatorTypes::Standard::ArrayRef::__coercion_generator
0000s0sTypes::Standard::ArrayRef::::__deep_explanationTypes::Standard::ArrayRef::__deep_explanation
0000s0sTypes::Standard::ArrayRef::::_croakTypes::Standard::ArrayRef::_croak
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1# INTERNAL MODULE: guts for ArrayRef type from Types::Standard.
2
3package Types::Standard::ArrayRef;
4
5253µs132µs
# spent 32µs within Types::Standard::ArrayRef::BEGIN@5 which was called: # once (32µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 5
use 5.008001;
# spent 32µs making 1 call to Types::Standard::ArrayRef::BEGIN@5
6235µs216µs
# spent 13µs (10+3) within Types::Standard::ArrayRef::BEGIN@6 which was called: # once (10µs+3µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 6
use strict;
# spent 13µs making 1 call to Types::Standard::ArrayRef::BEGIN@6 # spent 3µs making 1 call to strict::import
7245µs274µs
# spent 41µs (8+33) within Types::Standard::ArrayRef::BEGIN@7 which was called: # once (8µs+33µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 7
use warnings;
# spent 41µs making 1 call to Types::Standard::ArrayRef::BEGIN@7 # spent 33µs making 1 call to warnings::import
8
9
# spent 3µs within Types::Standard::ArrayRef::BEGIN@9 which was called: # once (3µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 12
BEGIN {
1010s $Types::Standard::ArrayRef::AUTHORITY = 'cpan:TOBYINK';
1114µs $Types::Standard::ArrayRef::VERSION = '2.000001';
12139µs13µs}
# spent 3µs making 1 call to Types::Standard::ArrayRef::BEGIN@9
13
1412µs$Types::Standard::ArrayRef::VERSION =~ tr/_//d;
15
16218µs13µs
# spent 3µs within Types::Standard::ArrayRef::BEGIN@16 which was called: # once (3µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 16
use Type::Tiny ();
# spent 3µs making 1 call to Types::Standard::ArrayRef::BEGIN@16
17217µs12µs
# spent 2µs within Types::Standard::ArrayRef::BEGIN@17 which was called: # once (2µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 17
use Types::Standard ();
# spent 2µs making 1 call to Types::Standard::ArrayRef::BEGIN@17
18246µs13µs
# spent 3µs within Types::Standard::ArrayRef::BEGIN@18 which was called: # once (3µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 18
use Types::TypeTiny ();
# spent 3µs making 1 call to Types::Standard::ArrayRef::BEGIN@18
19
20sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
21
222964µs246µs
# spent 27µs (8+19) within Types::Standard::ArrayRef::BEGIN@22 which was called: # once (8µs+19µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 22
no warnings;
# spent 27µs making 1 call to Types::Standard::ArrayRef::BEGIN@22 # spent 19µs making 1 call to warnings::unimport
23
24
# spent 2.66ms (95µs+2.57) within Types::Standard::ArrayRef::__constraint_generator which was called 4 times, avg 666µs/call: # 4 times (95µs+2.57ms) by Type::Tiny::parameterize at line 1044 of Type/Tiny.pm, avg 666µs/call
sub __constraint_generator {
2540s return Types::Standard::ArrayRef unless @_;
26
2742µs my $param = shift;
2846µs465µs Types::TypeTiny::is_TypeTiny( $param )
# spent 65µs making 4 calls to Types::TypeTiny::is_TypeTiny, avg 16µs/call
29 or _croak(
30 "Parameter to ArrayRef[`a] expected to be a type constraint; got $param" );
31
3243µs my ( $min, $max ) = ( 0, -1 );
3341µs $min = Types::Standard::assert_Int( shift ) if @_;
3442µs $max = Types::Standard::assert_Int( shift ) if @_;
35
3644µs4659µs my $param_compiled_check = $param->compiled_check;
# spent 659µs making 4 calls to Type::Tiny::compiled_check, avg 165µs/call
3740s my $xsub;
3849µs47µs if ( Type::Tiny::_USE_XS and $min == 0 and $max == -1 ) {
# spent 7µs making 4 calls to Type::Tiny::__ANON__[Type/Tiny.pm:55], avg 2µs/call
39 my $paramname = Type::Tiny::XS::is_known( $param_compiled_check );
40 $xsub = Type::Tiny::XS::get_coderef_for( "ArrayRef[$paramname]" )
41 if $paramname;
42 }
43 elsif ( Type::Tiny::_USE_MOUSE
44 and $param->_has_xsub
45 and $min == 0
46 and $max == -1 )
47 {
48 require Mouse::Util::TypeConstraints;
49 my $maker = "Mouse::Util::TypeConstraints"->can( "_parameterize_ArrayRef_for" );
50 $xsub = $maker->( $param ) if $maker;
51 }
52
53 return (
54 sub {
55 my $array = shift;
56 $param->check( $_ ) || return for @$array;
57 return !!1;
58 },
59423µs $xsub,
60 ) if $min == 0 and $max == -1;
61
62 return sub {
63 my $array = shift;
64 return if @$array < $min;
65 $param->check( $_ ) || return for @$array;
66 return !!1;
67 }
68 if $max == -1;
69
70 return sub {
71 my $array = shift;
72 return if @$array > $max;
73 $param->check( $_ ) || return for @$array;
74 return !!1;
75 }
76 if $min == 0;
77
78 return sub {
79 my $array = shift;
80 return if @$array < $min;
81 return if @$array > $max;
82 $param->check( $_ ) || return for @$array;
83 return !!1;
84 };
85} #/ sub __constraint_generator
86
87
# spent 86µs (40+46) within Types::Standard::ArrayRef::__inline_generator which was called 4 times, avg 22µs/call: # 4 times (40µs+46µs) by Type::Tiny::parameterize at line 1057 of Type/Tiny.pm, avg 22µs/call
sub __inline_generator {
8842µs my $param = shift;
8942µs my ( $min, $max ) = ( 0, -1 );
9041µs $min = shift if @_;
9141µs $max = shift if @_;
92
9342µs43µs my $param_compiled_check = $param->compiled_check;
# spent 3µs making 4 calls to Type::Tiny::compiled_check, avg 750ns/call
9440s my $xsubname;
95 if ( Type::Tiny::_USE_XS and $min == 0 and $max == -1 ) {
96 my $paramname = Type::Tiny::XS::is_known( $param_compiled_check );
97 $xsubname = Type::Tiny::XS::get_subname_for( "ArrayRef[$paramname]" );
98 }
99
10047µs443µs return unless $param->can_be_inlined;
# spent 43µs making 4 calls to Type::Tiny::can_be_inlined, avg 11µs/call
101
102
# spent 3.23ms (496µs+2.73) within Types::Standard::ArrayRef::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/ArrayRef.pm:121] which was called 24 times, avg 134µs/call: # 24 times (496µs+2.73ms) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 134µs/call
return sub {
1032412µs my $v = $_[1];
1042413µs return "$xsubname\($v\)" if $xsubname && !$Type::Tiny::AvoidCallbacks;
1052478µs4895µs my $p = Types::Standard::ArrayRef->inline_check( $v );
# spent 95µs making 24 calls to Types::Standard::ArrayRef, avg 4µs/call # spent 881µs making 24 calls to Type::Tiny::inline_check, avg 37µs/call, recursion: max depth 3, sum of overlapping time 881µs
106
1072413µs if ( $min != 0 ) {
108 $p .= sprintf( ' and @{%s} >= %d', $v, $min );
109 }
1102412µs if ( $max > 0 ) {
111 $p .= sprintf( ' and @{%s} <= %d', $v, $max );
112 }
113
1142446µs240s my $param_check = $param->inline_check( '$i' );
# spent 1.71ms making 24 calls to Type::Tiny::inline_check, avg 71µs/call, recursion: max depth 3, sum of overlapping time 1.71ms
1152470µs2447µs return $p if $param->{uniq} eq Types::Standard::Any->{uniq};
# spent 47µs making 24 calls to Types::Standard::Any, avg 2µs/call
116
1172474µs "$p and do { "
118 . "my \$ok = 1; "
119 . "for my \$i (\@{$v}) { "
120 . "(\$ok = 0, last) unless $param_check " . "}; " . "\$ok " . "}";
121421µs };
122} #/ sub __inline_generator
123
124sub __deep_explanation {
125 my ( $type, $value, $varname ) = @_;
126 my $param = $type->parameters->[0];
127 my ( $min, $max ) = ( 0, -1 );
128 $min = $type->parameters->[1] if @{ $type->parameters } > 1;
129 $max = $type->parameters->[2] if @{ $type->parameters } > 2;
130
131 if ( $min != 0 and @$value < $min ) {
132 return [
133 sprintf( '"%s" constrains array length at least %s', $type, $min ),
134 sprintf( '@{%s} is %d', $varname, scalar @$value ),
135 ];
136 }
137
138 if ( $max > 0 and @$value > $max ) {
139 return [
140 sprintf( '"%s" constrains array length at most %d', $type, $max ),
141 sprintf( '@{%s} is %d', $varname, scalar @$value ),
142 ];
143 }
144
145 for my $i ( 0 .. $#$value ) {
146 my $item = $value->[$i];
147 next if $param->check( $item );
148 return [
149 sprintf( '"%s" constrains each value in the array with "%s"', $type, $param ),
150 @{ $param->validate_explain( $item, sprintf( '%s->[%d]', $varname, $i ) ) },
151 ];
152 }
153
154 # This should never happen...
155 return; # uncoverable statement
156} #/ sub __deep_explanation
157
158# XXX: min and max need to be handled by coercion?
159sub __coercion_generator {
160 my ( $parent, $child, $param ) = @_;
161 return unless $param->has_coercion;
162
163 my $coercable_item = $param->coercion->_source_type_union;
164 my $C = "Type::Coercion"->new( type_constraint => $child );
165
166 if ( $param->coercion->can_be_inlined and $coercable_item->can_be_inlined ) {
167 $C->add_type_coercions(
168 $parent => Types::Standard::Stringable {
169 my @code;
170 push @code, 'do { my ($orig, $return_orig, @new) = ($_, 0);';
171 push @code, 'for (@$orig) {';
172 push @code,
173 sprintf(
174 '++$return_orig && last unless (%s);',
175 $coercable_item->inline_check( '$_' )
176 );
177 push @code,
178 sprintf(
179 'push @new, (%s);',
180 $param->coercion->inline_coercion( '$_' )
181 );
182 push @code, '}';
183 push @code, '$return_orig ? $orig : \\@new';
184 push @code, '}';
185 "@code";
186 }
187 );
188 } #/ if ( $param->coercion->...)
189 else {
190 $C->add_type_coercions(
191 $parent => sub {
192 my $value = @_ ? $_[0] : $_;
193 my @new;
194 for my $item ( @$value ) {
195 return $value unless $coercable_item->check( $item );
196 push @new, $param->coerce( $item );
197 }
198 return \@new;
199 },
200 );
201 } #/ else [ if ( $param->coercion->...)]
202
203 return $C;
204} #/ sub __coercion_generator
205
20614µs1;