← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:57:08 2022
Reported on Wed Dec 14 16:00:35 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/Map.pm
StatementsExecuted 47 statements in 2.09ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111156µs156µsTypes::Standard::Map::::BEGIN@5Types::Standard::Map::BEGIN@5
31156µs692µsTypes::Standard::Map::::__ANON__[:87]Types::Standard::Map::__ANON__[:87]
11146µs3.40msTypes::Standard::Map::::__constraint_generatorTypes::Standard::Map::__constraint_generator
11123µs42µsTypes::Standard::Map::::BEGIN@6Types::Standard::Map::BEGIN@6
11116µs64µsTypes::Standard::Map::::__inline_generatorTypes::Standard::Map::__inline_generator
11112µs41µsTypes::Standard::Map::::BEGIN@24Types::Standard::Map::BEGIN@24
11110µs94µsTypes::Standard::Map::::BEGIN@7Types::Standard::Map::BEGIN@7
1117µs7µsTypes::Standard::Map::::BEGIN@16Types::Standard::Map::BEGIN@16
1115µs5µsTypes::Standard::Map::::BEGIN@17Types::Standard::Map::BEGIN@17
1113µs3µsTypes::Standard::Map::::BEGIN@18Types::Standard::Map::BEGIN@18
1113µs3µsTypes::Standard::Map::::BEGIN@9Types::Standard::Map::BEGIN@9
0000s0sTypes::Standard::Map::::__ANON__[:168]Types::Standard::Map::__ANON__[:168]
0000s0sTypes::Standard::Map::::__ANON__[:186]Types::Standard::Map::__ANON__[:186]
0000s0sTypes::Standard::Map::::__ANON__[:200]Types::Standard::Map::__ANON__[:200]
0000s0sTypes::Standard::Map::::__ANON__[:214]Types::Standard::Map::__ANON__[:214]
0000s0sTypes::Standard::Map::::__ANON__[:56]Types::Standard::Map::__ANON__[:56]
0000s0sTypes::Standard::Map::::__coercion_generatorTypes::Standard::Map::__coercion_generator
0000s0sTypes::Standard::Map::::__deep_explanationTypes::Standard::Map::__deep_explanation
0000s0sTypes::Standard::Map::::__hashref_allows_keyTypes::Standard::Map::__hashref_allows_key
0000s0sTypes::Standard::Map::::__hashref_allows_valueTypes::Standard::Map::__hashref_allows_value
0000s0sTypes::Standard::Map::::_croakTypes::Standard::Map::_croak
0000s0sTypes::Standard::Map::::my_hashref_allows_keyTypes::Standard::Map::my_hashref_allows_key
0000s0sTypes::Standard::Map::::my_hashref_allows_valueTypes::Standard::Map::my_hashref_allows_value
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 Map type from Types::Standard.
2
3package Types::Standard::Map;
4
52162µs1156µs
# spent 156µs within Types::Standard::Map::BEGIN@5 which was called: # once (156µ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 156µs making 1 call to Types::Standard::Map::BEGIN@5
6260µs261µs
# spent 42µs (23+19) within Types::Standard::Map::BEGIN@6 which was called: # once (23µs+19µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 6
use strict;
# spent 42µs making 1 call to Types::Standard::Map::BEGIN@6 # spent 19µs making 1 call to strict::import
7264µs2178µs
# spent 94µs (10+84) within Types::Standard::Map::BEGIN@7 which was called: # once (10µs+84µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 7
use warnings;
# spent 94µs making 1 call to Types::Standard::Map::BEGIN@7 # spent 84µs making 1 call to warnings::import
8
9
# spent 3µs within Types::Standard::Map::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::Map::AUTHORITY = 'cpan:TOBYINK';
1115µs $Types::Standard::Map::VERSION = '2.000001';
12153µs13µs}
# spent 3µs making 1 call to Types::Standard::Map::BEGIN@9
13
1411µs$Types::Standard::Map::VERSION =~ tr/_//d;
15
16223µs17µs
# spent 7µs within Types::Standard::Map::BEGIN@16 which was called: # once (7µ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 7µs making 1 call to Types::Standard::Map::BEGIN@16
17216µs15µs
# spent 5µs within Types::Standard::Map::BEGIN@17 which was called: # once (5µ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 5µs making 1 call to Types::Standard::Map::BEGIN@17
18277µs13µs
# spent 3µs within Types::Standard::Map::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::Map::BEGIN@18
19
20sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
21
2217µs122µsmy $meta = Types::Standard->meta;
# spent 22µs making 1 call to Type::Library::meta
23
2421.55ms270µs
# spent 41µs (12+29) within Types::Standard::Map::BEGIN@24 which was called: # once (12µs+29µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 24
no warnings;
# spent 41µs making 1 call to Types::Standard::Map::BEGIN@24 # spent 29µs making 1 call to warnings::unimport
25
26
# spent 3.40ms (46µs+3.36) within Types::Standard::Map::__constraint_generator which was called: # once (46µs+3.36ms) by Type::Tiny::parameterize at line 1044 of Type/Tiny.pm
sub __constraint_generator {
2710s return $meta->get_type( 'Map' ) unless @_;
28
2911µs my ( $keys, $values ) = @_;
3013µs137µs Types::TypeTiny::is_TypeTiny( $keys )
# spent 37µs making 1 call to Types::TypeTiny::is_TypeTiny
31 or _croak(
32 "First parameter to Map[`k,`v] expected to be a type constraint; got $keys" );
3312µs114µs Types::TypeTiny::is_TypeTiny( $values )
# spent 14µs making 1 call to Types::TypeTiny::is_TypeTiny
34 or _croak(
35 "Second parameter to Map[`k,`v] expected to be a type constraint; got $values"
36 );
37
3810s my @xsub;
39 if ( Type::Tiny::_USE_XS ) {
40 my @known = map {
41 my $known = Type::Tiny::XS::is_known( $_->compiled_check );
42 defined( $known ) ? $known : ();
43 } ( $keys, $values );
44
45 if ( @known == 2 ) {
46 my $xsub = Type::Tiny::XS::get_coderef_for( sprintf "Map[%s,%s]", @known );
47 push @xsub, $xsub if $xsub;
48 }
49 } #/ if ( Type::Tiny::_USE_XS)
50
51 sub {
52 my $hash = shift;
53 $keys->check( $_ ) || return for keys %$hash;
54 $values->check( $_ ) || return for values %$hash;
55 return !!1;
56113µs }, @xsub;
57} #/ sub __constraint_generator
58
59
# spent 64µs (16+48) within Types::Standard::Map::__inline_generator which was called: # once (16µs+48µs) by Type::Tiny::parameterize at line 1057 of Type/Tiny.pm
sub __inline_generator {
6011µs my ( $k, $v ) = @_;
6114µs248µs return unless $k->can_be_inlined && $v->can_be_inlined;
# spent 48µs making 2 calls to Type::Tiny::can_be_inlined, avg 24µs/call
62
6311µs my $xsubname;
64 if ( Type::Tiny::_USE_XS ) {
65 my @known = map {
66 my $known = Type::Tiny::XS::is_known( $_->compiled_check );
67 defined( $known ) ? $known : ();
68 } ( $k, $v );
69
70 if ( @known == 2 ) {
71 $xsubname = Type::Tiny::XS::get_subname_for( sprintf "Map[%s,%s]", @known );
72 }
73 } #/ if ( Type::Tiny::_USE_XS)
74
75
# spent 692µs (56+636) within Types::Standard::Map::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/Map.pm:87] which was called 3 times, avg 231µs/call: # 3 times (56µs+636µs) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 231µs/call
return sub {
7632µs my $h = $_[1];
7732µs return "$xsubname\($h\)" if $xsubname && !$Type::Tiny::AvoidCallbacks;
78310µs612µs my $p = Types::Standard::HashRef->inline_check( $h );
# spent 12µs making 3 calls to Types::Standard::HashRef, avg 4µs/call # spent 88µs making 3 calls to Type::Tiny::inline_check, avg 29µs/call, recursion: max depth 1, sum of overlapping time 88µs
7934µs30s my $k_check = $k->inline_check( '$k' );
# spent 453µs making 3 calls to Type::Tiny::inline_check, avg 151µs/call, recursion: max depth 1, sum of overlapping time 453µs
8035µs30s my $v_check = $v->inline_check( '$v' );
# spent 83µs making 3 calls to Type::Tiny::inline_check, avg 28µs/call, recursion: max depth 1, sum of overlapping time 83µs
81316µs "$p and do { "
82 . "my \$ok = 1; "
83 . "for my \$v (values \%{$h}) { "
84 . "(\$ok = 0, last) unless $v_check " . "}; "
85 . "for my \$k (keys \%{$h}) { "
86 . "(\$ok = 0, last) unless $k_check " . "}; " . "\$ok " . "}";
8716µs };
88} #/ sub __inline_generator
89
90sub __deep_explanation {
91 require B;
92 my ( $type, $value, $varname ) = @_;
93 my ( $kparam, $vparam ) = @{ $type->parameters };
94
95 for my $k ( sort keys %$value ) {
96 unless ( $kparam->check( $k ) ) {
97 return [
98 sprintf( '"%s" constrains each key in the hash with "%s"', $type, $kparam ),
99 @{
100 $kparam->validate_explain(
101 $k, sprintf( 'key %s->{%s}', $varname, B::perlstring( $k ) )
102 )
103 },
104 ];
105 } #/ unless ( $kparam->check( $k...))
106
107 unless ( $vparam->check( $value->{$k} ) ) {
108 return [
109 sprintf( '"%s" constrains each value in the hash with "%s"', $type, $vparam ),
110 @{
111 $vparam->validate_explain(
112 $value->{$k}, sprintf( '%s->{%s}', $varname, B::perlstring( $k ) )
113 )
114 },
115 ];
116 } #/ unless ( $vparam->check( $value...))
117 } #/ for my $k ( sort keys %$value)
118
119 # This should never happen...
120 return; # uncoverable statement
121} #/ sub __deep_explanation
122
123sub __coercion_generator {
124 my ( $parent, $child, $kparam, $vparam ) = @_;
125 return unless $kparam->has_coercion || $vparam->has_coercion;
126
127 my $kcoercable_item =
128 $kparam->has_coercion
129 ? $kparam->coercion->_source_type_union
130 : $kparam;
131 my $vcoercable_item =
132 $vparam->has_coercion
133 ? $vparam->coercion->_source_type_union
134 : $vparam;
135 my $C = "Type::Coercion"->new( type_constraint => $child );
136
137 if ( ( !$kparam->has_coercion or $kparam->coercion->can_be_inlined )
138 and ( !$vparam->has_coercion or $vparam->coercion->can_be_inlined )
139 and $kcoercable_item->can_be_inlined
140 and $vcoercable_item->can_be_inlined )
141 {
142 $C->add_type_coercions(
143 $parent => Types::Standard::Stringable {
144 my @code;
145 push @code, 'do { my ($orig, $return_orig, %new) = ($_, 0);';
146 push @code, 'for (keys %$orig) {';
147 push @code,
148 sprintf(
149 '++$return_orig && last unless (%s);',
150 $kcoercable_item->inline_check( '$_' )
151 );
152 push @code,
153 sprintf(
154 '++$return_orig && last unless (%s);',
155 $vcoercable_item->inline_check( '$orig->{$_}' )
156 );
157 push @code, sprintf(
158 '$new{(%s)} = (%s);',
159 $kparam->has_coercion ? $kparam->coercion->inline_coercion( '$_' ) : '$_',
160 $vparam->has_coercion
161 ? $vparam->coercion->inline_coercion( '$orig->{$_}' )
162 : '$orig->{$_}',
163 );
164 push @code, '}';
165 push @code, '$return_orig ? $orig : \\%new';
166 push @code, '}';
167 "@code";
168 }
169 );
170 } #/ if ( ( !$kparam->has_coercion...))
171 else {
172 $C->add_type_coercions(
173 $parent => sub {
174 my $value = @_ ? $_[0] : $_;
175 my %new;
176 for my $k ( keys %$value ) {
177 return $value
178 unless $kcoercable_item->check( $k )
179 && $vcoercable_item->check( $value->{$k} );
180 $new{ $kparam->has_coercion ? $kparam->coerce( $k ) : $k } =
181 $vparam->has_coercion
182 ? $vparam->coerce( $value->{$k} )
183 : $value->{$k};
184 }
185 return \%new;
186 },
187 );
188 } #/ else [ if ( ( !$kparam->has_coercion...))]
189
190 return $C;
191} #/ sub __coercion_generator
192
193sub __hashref_allows_key {
194 my $self = shift;
195 my ( $key ) = @_;
196
197 return Types::Standard::is_Str( $key ) if $self == Types::Standard::Map();
198
199 my $map = $self->find_parent(
200 sub { $_->has_parent && $_->parent == Types::Standard::Map() } );
201 my ( $kcheck, $vcheck ) = @{ $map->parameters };
202
203 ( $kcheck or Types::Standard::Any() )->check( $key );
204} #/ sub __hashref_allows_key
205
206sub __hashref_allows_value {
207 my $self = shift;
208 my ( $key, $value ) = @_;
209
210 return !!0 unless $self->my_hashref_allows_key( $key );
211 return !!1 if $self == Types::Standard::Map();
212
213 my $map = $self->find_parent(
214 sub { $_->has_parent && $_->parent == Types::Standard::Map() } );
215 my ( $kcheck, $vcheck ) = @{ $map->parameters };
216
217 ( $kcheck or Types::Standard::Any() )->check( $key )
218 and ( $vcheck or Types::Standard::Any() )->check( $value );
219} #/ sub __hashref_allows_value
220
22118µs1;