| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/Tuple.pm |
| Statements | Executed 129 statements in 2.40ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 8 | 1 | 1 | 159µs | 1.50ms | Types::Standard::Tuple::__ANON__[:164] |
| 2 | 1 | 1 | 111µs | 5.29ms | Types::Standard::Tuple::__constraint_generator |
| 1 | 1 | 1 | 56µs | 56µs | Types::Standard::Tuple::BEGIN@5 |
| 2 | 1 | 1 | 51µs | 1.81ms | Types::Standard::Tuple::__inline_generator |
| 1 | 1 | 1 | 35µs | 37µs | Types::Standard::Tuple::BEGIN@6 |
| 1 | 1 | 1 | 29µs | 29µs | Types::Standard::Tuple::BEGIN@18 |
| 1 | 1 | 1 | 9µs | 28µs | Types::Standard::Tuple::BEGIN@338 |
| 1 | 1 | 1 | 5µs | 30µs | Types::Standard::Tuple::BEGIN@7 |
| 1 | 1 | 1 | 3µs | 3µs | Types::Standard::Tuple::BEGIN@16 |
| 1 | 1 | 1 | 3µs | 15µs | Types::Standard::Tuple::BEGIN@25 |
| 2 | 1 | 1 | 3µs | 3µs | Types::Standard::Tuple::CORE:sort (opcode) |
| 1 | 1 | 1 | 2µs | 2µs | Types::Standard::Tuple::BEGIN@17 |
| 1 | 1 | 1 | 2µs | 2µs | Types::Standard::Tuple::BEGIN@9 |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::Tuple::__ANON__[:310] |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::Tuple::__ANON__[:350] |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::Tuple::__ANON__[:91] |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::Tuple::__coercion_generator |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::Tuple::__deep_explanation |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::Tuple::_croak |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # INTERNAL MODULE: guts for Tuple type from Types::Standard. | ||||
| 2 | |||||
| 3 | package Types::Standard::Tuple; | ||||
| 4 | |||||
| 5 | 2 | 36µs | 1 | 56µs | # spent 56µs within Types::Standard::Tuple::BEGIN@5 which was called:
# once (56µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 5 # spent 56µs making 1 call to Types::Standard::Tuple::BEGIN@5 |
| 6 | 2 | 48µs | 2 | 39µs | # spent 37µs (35+2) within Types::Standard::Tuple::BEGIN@6 which was called:
# once (35µs+2µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 6 # spent 37µs making 1 call to Types::Standard::Tuple::BEGIN@6
# spent 2µs making 1 call to strict::import |
| 7 | 2 | 49µs | 2 | 55µs | # spent 30µs (5+25) within Types::Standard::Tuple::BEGIN@7 which was called:
# once (5µs+25µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 7 # spent 30µs making 1 call to Types::Standard::Tuple::BEGIN@7
# spent 25µs making 1 call to warnings::import |
| 8 | |||||
| 9 | # spent 2µs within Types::Standard::Tuple::BEGIN@9 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 12 | ||||
| 10 | 1 | 0s | $Types::Standard::Tuple::AUTHORITY = 'cpan:TOBYINK'; | ||
| 11 | 1 | 1µs | $Types::Standard::Tuple::VERSION = '2.000001'; | ||
| 12 | 1 | 25µs | 1 | 2µs | } # spent 2µs making 1 call to Types::Standard::Tuple::BEGIN@9 |
| 13 | |||||
| 14 | 1 | 1µs | $Types::Standard::Tuple::VERSION =~ tr/_//d; | ||
| 15 | |||||
| 16 | 2 | 11µs | 1 | 3µs | # spent 3µs within Types::Standard::Tuple::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 # spent 3µs making 1 call to Types::Standard::Tuple::BEGIN@16 |
| 17 | 2 | 37µs | 1 | 2µs | # spent 2µs within Types::Standard::Tuple::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 # spent 2µs making 1 call to Types::Standard::Tuple::BEGIN@17 |
| 18 | 2 | 41µs | 1 | 29µs | # spent 29µs within Types::Standard::Tuple::BEGIN@18 which was called:
# once (29µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 18 # spent 29µs making 1 call to Types::Standard::Tuple::BEGIN@18 |
| 19 | |||||
| 20 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
| 21 | |||||
| 22 | 1 | 2µs | 1 | 5µs | my $_Optional = Types::Standard::Optional; # spent 5µs making 1 call to Types::Standard::Optional |
| 23 | 1 | 34µs | 1 | 35µs | my $_Slurpy = Types::Standard::Slurpy; # spent 35µs making 1 call to Types::Standard::Slurpy |
| 24 | |||||
| 25 | 2 | 1.57ms | 2 | 27µs | # spent 15µs (3+12) within Types::Standard::Tuple::BEGIN@25 which was called:
# once (3µs+12µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 25 # spent 15µs making 1 call to Types::Standard::Tuple::BEGIN@25
# spent 12µs making 1 call to warnings::unimport |
| 26 | |||||
| 27 | # spent 5.29ms (111µs+5.18) within Types::Standard::Tuple::__constraint_generator which was called 2 times, avg 2.64ms/call:
# 2 times (111µs+5.18ms) by Type::Tiny::parameterize at line 1044 of Type/Tiny.pm, avg 2.64ms/call | ||||
| 28 | 2 | 7µs | 4 | 726µs | my $slurpy = # spent 693µs making 2 calls to Type::Tiny::is_strictly_a_type_of, avg 346µs/call
# spent 33µs making 2 calls to Types::TypeTiny::is_TypeTiny, avg 16µs/call |
| 29 | @_ | ||||
| 30 | && Types::TypeTiny::is_TypeTiny( $_[-1] ) | ||||
| 31 | && $_[-1]->is_strictly_a_type_of( $_Slurpy ) | ||||
| 32 | ? pop | ||||
| 33 | : undef; | ||||
| 34 | |||||
| 35 | 2 | 2µs | my @constraints = @_; | ||
| 36 | 2 | 2µs | for ( @constraints ) { | ||
| 37 | 4 | 5µs | 4 | 46µs | Types::TypeTiny::is_TypeTiny( $_ ) # spent 46µs making 4 calls to Types::TypeTiny::is_TypeTiny, avg 12µs/call |
| 38 | or | ||||
| 39 | _croak( "Parameters to Tuple[...] expected to be type constraints; got $_" ); | ||||
| 40 | } | ||||
| 41 | |||||
| 42 | # By god, the Type::Tiny::XS API is currently horrible | ||||
| 43 | 2 | 1µs | my @xsub; | ||
| 44 | if ( Type::Tiny::_USE_XS and !$slurpy ) { | ||||
| 45 | my @known = map { | ||||
| 46 | my $known; | ||||
| 47 | $known = Type::Tiny::XS::is_known( $_->compiled_check ) | ||||
| 48 | unless $_->is_strictly_a_type_of( $_Optional ); | ||||
| 49 | defined( $known ) ? $known : (); | ||||
| 50 | } @constraints; | ||||
| 51 | |||||
| 52 | if ( @known == @constraints ) { | ||||
| 53 | my $xsub = Type::Tiny::XS::get_coderef_for( | ||||
| 54 | sprintf( "Tuple[%s]", join( ',', @known ) ) ); | ||||
| 55 | push @xsub, $xsub if $xsub; | ||||
| 56 | } | ||||
| 57 | } #/ if ( Type::Tiny::_USE_XS...) | ||||
| 58 | |||||
| 59 | 2 | 9µs | 4 | 1.33ms | my @is_optional = map !!$_->is_strictly_a_type_of( $_Optional ), @constraints; # spent 1.33ms making 4 calls to Type::Tiny::is_strictly_a_type_of, avg 332µs/call |
| 60 | 2 | 0s | my $slurp_hash = $slurpy && $slurpy->my_slurp_into eq 'HASH'; | ||
| 61 | 2 | 2µs | my $slurp_any = $slurpy && $slurpy->my_unslurpy->equals( Types::Standard::Any ); | ||
| 62 | |||||
| 63 | 2 | 10µs | 2 | 3µs | my @sorted_is_optional = sort @is_optional; # spent 3µs making 2 calls to Types::Standard::Tuple::CORE:sort, avg 2µs/call |
| 64 | 2 | 3µs | join( "|", @sorted_is_optional ) eq join( "|", @is_optional ) | ||
| 65 | or _croak( | ||||
| 66 | "Optional parameters to Tuple[...] cannot precede required parameters" ); | ||||
| 67 | |||||
| 68 | sub { | ||||
| 69 | my $value = $_[0]; | ||||
| 70 | if ( $#constraints < $#$value ) { | ||||
| 71 | return !!0 unless $slurpy; | ||||
| 72 | my $tmp; | ||||
| 73 | if ( $slurp_hash ) { | ||||
| 74 | ( $#$value - $#constraints + 1 ) % 2 or return; | ||||
| 75 | $tmp = +{ @$value[ $#constraints + 1 .. $#$value ] }; | ||||
| 76 | $slurpy->check( $tmp ) or return; | ||||
| 77 | } | ||||
| 78 | elsif ( not $slurp_any ) { | ||||
| 79 | $tmp = +[ @$value[ $#constraints + 1 .. $#$value ] ]; | ||||
| 80 | $slurpy->check( $tmp ) or return; | ||||
| 81 | } | ||||
| 82 | } #/ if ( $#constraints < $#$value) | ||||
| 83 | for my $i ( 0 .. $#constraints ) { | ||||
| 84 | ( $i > $#$value ) | ||||
| 85 | and return !!$is_optional[$i]; | ||||
| 86 | |||||
| 87 | $constraints[$i]->check( $value->[$i] ) | ||||
| 88 | or return !!0; | ||||
| 89 | } | ||||
| 90 | return !!1; | ||||
| 91 | 2 | 13µs | }, @xsub; | ||
| 92 | } #/ sub __constraint_generator | ||||
| 93 | |||||
| 94 | # spent 1.81ms (51µs+1.76) within Types::Standard::Tuple::__inline_generator which was called 2 times, avg 903µs/call:
# 2 times (51µs+1.76ms) by Type::Tiny::parameterize at line 1057 of Type/Tiny.pm, avg 903µs/call | ||||
| 95 | 2 | 5µs | 4 | 562µs | my $slurpy = # spent 542µs making 2 calls to Type::Tiny::is_strictly_a_type_of, avg 271µs/call
# spent 20µs making 2 calls to Types::TypeTiny::is_TypeTiny, avg 10µs/call |
| 96 | @_ | ||||
| 97 | && Types::TypeTiny::is_TypeTiny( $_[-1] ) | ||||
| 98 | && $_[-1]->is_strictly_a_type_of( $_Slurpy ) | ||||
| 99 | ? pop | ||||
| 100 | : undef; | ||||
| 101 | 2 | 2µs | my @constraints = @_; | ||
| 102 | |||||
| 103 | 6 | 9µs | 4 | 30µs | return if grep { not $_->can_be_inlined } @constraints; # spent 28µs making 2 calls to Type::Tiny::can_be_inlined, avg 14µs/call
# spent 2µs making 2 calls to Type::Tiny::Enum::can_be_inlined, avg 1µs/call |
| 104 | 2 | 0s | return if defined $slurpy && !$slurpy->can_be_inlined; | ||
| 105 | |||||
| 106 | 2 | 1µs | my $xsubname; | ||
| 107 | if ( Type::Tiny::_USE_XS and !$slurpy ) { | ||||
| 108 | my @known = map { | ||||
| 109 | my $known; | ||||
| 110 | $known = Type::Tiny::XS::is_known( $_->compiled_check ) | ||||
| 111 | unless $_->is_strictly_a_type_of( $_Optional ); | ||||
| 112 | defined( $known ) ? $known : (); | ||||
| 113 | } @constraints; | ||||
| 114 | |||||
| 115 | if ( @known == @constraints ) { | ||||
| 116 | $xsubname = Type::Tiny::XS::get_subname_for( | ||||
| 117 | sprintf( "Tuple[%s]", join( ',', @known ) ) ); | ||||
| 118 | } | ||||
| 119 | } #/ if ( Type::Tiny::_USE_XS...) | ||||
| 120 | |||||
| 121 | 2 | 0s | my $tmpl = "do { my \$tmp = +[\@{%s}[%d..\$#{%s}]]; %s }"; | ||
| 122 | 2 | 0s | my $slurpy_any; | ||
| 123 | 2 | 1µs | if ( defined $slurpy ) { | ||
| 124 | $tmpl = | ||||
| 125 | 'do { my ($orig, $from, $to) = (%s, %d, $#{%s});' | ||||
| 126 | . '(($to-$from) %% 2) and do { my $tmp = +{@{$orig}[$from..$to]}; %s }' | ||||
| 127 | . '}' | ||||
| 128 | if $slurpy->my_slurp_into eq 'HASH'; | ||||
| 129 | $slurpy_any = 1 | ||||
| 130 | if $slurpy->my_unslurpy->equals( Types::Standard::Any ); | ||||
| 131 | } | ||||
| 132 | |||||
| 133 | 2 | 6µs | 4 | 1.16ms | my @is_optional = map !!$_->is_strictly_a_type_of( $_Optional ), @constraints; # spent 1.16ms making 4 calls to Type::Tiny::is_strictly_a_type_of, avg 291µs/call |
| 134 | 2 | 2µs | my $min = 0+ grep !$_, @is_optional; | ||
| 135 | |||||
| 136 | # spent 1.50ms (159µs+1.34) within Types::Standard::Tuple::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/Tuple.pm:164] which was called 8 times, avg 188µs/call:
# 8 times (159µs+1.34ms) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 188µs/call | ||||
| 137 | 8 | 4µs | my $v = $_[1]; | ||
| 138 | 8 | 2µs | return "$xsubname\($v\)" if $xsubname && !$Type::Tiny::AvoidCallbacks; | ||
| 139 | join " and ", | ||||
| 140 | Types::Standard::ArrayRef->inline_check( $v ), | ||||
| 141 | ( | ||||
| 142 | ( scalar @constraints == $min and not $slurpy ) | ||||
| 143 | ? "\@{$v} == $min" | ||||
| 144 | : sprintf( | ||||
| 145 | "(\@{$v} == $min or (\@{$v} > $min and \@{$v} <= ${\(1+$#constraints)}) or (\@{$v} > ${\(1+$#constraints)} and %s))", | ||||
| 146 | ( | ||||
| 147 | $slurpy_any ? '!!1' | ||||
| 148 | : ( | ||||
| 149 | $slurpy | ||||
| 150 | ? sprintf( $tmpl, $v, $#constraints + 1, $v, $slurpy->inline_check( '$tmp' ) ) | ||||
| 151 | : sprintf( "\@{$v} <= %d", scalar @constraints ) | ||||
| 152 | ) | ||||
| 153 | ), | ||||
| 154 | ) | ||||
| 155 | ), | ||||
| 156 | map { | ||||
| 157 | 24 | 103µs | 32 | 158µs | my $inline = $constraints[$_]->inline_check( "$v\->[$_]" ); # spent 129µs making 8 calls to Type::Tiny::Enum::inline_check, avg 16µs/call
# spent 29µs making 8 calls to Types::Standard::ArrayRef, avg 4µs/call
# spent 1.19ms making 16 calls to Type::Tiny::inline_check, avg 74µs/call, recursion: max depth 2, sum of overlapping time 1.19ms |
| 158 | 16 | 12µs | $inline eq '(!!1)' ? () | ||
| 159 | : ( | ||||
| 160 | $is_optional[$_] ? sprintf( '(@{%s} <= %d or %s)', $v, $_, $inline ) | ||||
| 161 | : $inline | ||||
| 162 | ); | ||||
| 163 | } 0 .. $#constraints; | ||||
| 164 | 2 | 22µs | }; | ||
| 165 | } #/ sub __inline_generator | ||||
| 166 | |||||
| 167 | sub __deep_explanation { | ||||
| 168 | my ( $type, $value, $varname ) = @_; | ||||
| 169 | |||||
| 170 | my @constraints = @{ $type->parameters }; | ||||
| 171 | my $slurpy = | ||||
| 172 | @constraints | ||||
| 173 | && Types::TypeTiny::is_TypeTiny( $constraints[-1] ) | ||||
| 174 | && $constraints[-1]->is_strictly_a_type_of( $_Slurpy ) | ||||
| 175 | ? pop( @constraints ) | ||||
| 176 | : undef; | ||||
| 177 | @constraints = map Types::TypeTiny::to_TypeTiny( $_ ), @constraints; | ||||
| 178 | |||||
| 179 | if ( @constraints < @$value and not $slurpy ) { | ||||
| 180 | return [ | ||||
| 181 | sprintf( | ||||
| 182 | '"%s" expects at most %d values in the array', $type, scalar( @constraints ) | ||||
| 183 | ), | ||||
| 184 | sprintf( '%d values found; too many', scalar( @$value ) ), | ||||
| 185 | ]; | ||||
| 186 | } | ||||
| 187 | |||||
| 188 | for my $i ( 0 .. $#constraints ) { | ||||
| 189 | next | ||||
| 190 | if $constraints[$i] | ||||
| 191 | ->is_strictly_a_type_of( Types::Standard::Optional ) | ||||
| 192 | && $i > $#$value; | ||||
| 193 | next if $constraints[$i]->check( $value->[$i] ); | ||||
| 194 | |||||
| 195 | return [ | ||||
| 196 | sprintf( | ||||
| 197 | '"%s" constrains value at index %d of array with "%s"', $type, $i, | ||||
| 198 | $constraints[$i] | ||||
| 199 | ), | ||||
| 200 | @{ | ||||
| 201 | $constraints[$i] | ||||
| 202 | ->validate_explain( $value->[$i], sprintf( '%s->[%s]', $varname, $i ) ) | ||||
| 203 | }, | ||||
| 204 | ]; | ||||
| 205 | } #/ for my $i ( 0 .. $#constraints) | ||||
| 206 | |||||
| 207 | if ( defined( $slurpy ) ) { | ||||
| 208 | my $tmp = | ||||
| 209 | $slurpy->my_slurp_into eq 'HASH' | ||||
| 210 | ? +{ @$value[ $#constraints + 1 .. $#$value ] } | ||||
| 211 | : +[ @$value[ $#constraints + 1 .. $#$value ] ]; | ||||
| 212 | $slurpy->check( $tmp ) | ||||
| 213 | or return [ | ||||
| 214 | sprintf( | ||||
| 215 | 'Array elements from index %d are slurped into a %s which is constrained with "%s"', | ||||
| 216 | $#constraints + 1, | ||||
| 217 | ( $slurpy->my_slurp_into eq 'HASH' ) ? 'hashref' : 'arrayref', | ||||
| 218 | ( $slurpy->my_unslurpy || $slurpy ), | ||||
| 219 | ), | ||||
| 220 | @{ ( $slurpy->my_unslurpy || $slurpy )->validate_explain( $tmp, '$SLURPY' ) }, | ||||
| 221 | ]; | ||||
| 222 | } #/ if ( defined( $slurpy ...)) | ||||
| 223 | |||||
| 224 | # This should never happen... | ||||
| 225 | return; # uncoverable statement | ||||
| 226 | } #/ sub __deep_explanation | ||||
| 227 | |||||
| 228 | 1 | 0s | my $label_counter = 0; | ||
| 229 | |||||
| 230 | sub __coercion_generator { | ||||
| 231 | my ( $parent, $child, @tuple ) = @_; | ||||
| 232 | |||||
| 233 | my $slurpy = | ||||
| 234 | @tuple | ||||
| 235 | && Types::TypeTiny::is_TypeTiny( $tuple[-1] ) | ||||
| 236 | && $tuple[-1]->is_strictly_a_type_of( $_Slurpy ) | ||||
| 237 | ? pop( @tuple ) | ||||
| 238 | : undef; | ||||
| 239 | |||||
| 240 | my $child_coercions_exist = 0; | ||||
| 241 | my $all_inlinable = 1; | ||||
| 242 | for my $tc ( @tuple, ( $slurpy ? $slurpy : () ) ) { | ||||
| 243 | $all_inlinable = 0 if !$tc->can_be_inlined; | ||||
| 244 | $all_inlinable = 0 if $tc->has_coercion && !$tc->coercion->can_be_inlined; | ||||
| 245 | $child_coercions_exist++ if $tc->has_coercion; | ||||
| 246 | } | ||||
| 247 | |||||
| 248 | return unless $child_coercions_exist; | ||||
| 249 | my $C = "Type::Coercion"->new( type_constraint => $child ); | ||||
| 250 | |||||
| 251 | my $slurpy_is_hashref = $slurpy && $slurpy->my_slurp_into eq 'HASH'; | ||||
| 252 | |||||
| 253 | if ( $all_inlinable ) { | ||||
| 254 | $C->add_type_coercions( | ||||
| 255 | $parent => Types::Standard::Stringable { | ||||
| 256 | my $label = sprintf( "TUPLELABEL%d", ++$label_counter ); | ||||
| 257 | my @code; | ||||
| 258 | push @code, 'do { my ($orig, $return_orig, $tmp, @new) = ($_, 0);'; | ||||
| 259 | push @code, "$label: {"; | ||||
| 260 | push @code, | ||||
| 261 | sprintf( | ||||
| 262 | '(($return_orig = 1), last %s) if @$orig > %d;', $label, | ||||
| 263 | scalar @tuple | ||||
| 264 | ) unless $slurpy; | ||||
| 265 | for my $i ( 0 .. $#tuple ) { | ||||
| 266 | my $ct = $tuple[$i]; | ||||
| 267 | my $ct_coerce = $ct->has_coercion; | ||||
| 268 | my $ct_optional = $ct->is_a_type_of( Types::Standard::Optional ); | ||||
| 269 | |||||
| 270 | push @code, sprintf( | ||||
| 271 | 'if (@$orig > %d) { $tmp = %s; (%s) ? ($new[%d]=$tmp) : (($return_orig=1), last %s) }', | ||||
| 272 | $i, | ||||
| 273 | $ct_coerce | ||||
| 274 | ? $ct->coercion->inline_coercion( "\$orig->[$i]" ) | ||||
| 275 | : "\$orig->[$i]", | ||||
| 276 | $ct->inline_check( '$tmp' ), | ||||
| 277 | $i, | ||||
| 278 | $label, | ||||
| 279 | ); | ||||
| 280 | } #/ for my $i ( 0 .. $#tuple) | ||||
| 281 | if ( $slurpy ) { | ||||
| 282 | my $size = @tuple; | ||||
| 283 | push @code, sprintf( 'if (@$orig > %d) {', $size ); | ||||
| 284 | push @code, sprintf( | ||||
| 285 | ( | ||||
| 286 | $slurpy_is_hashref | ||||
| 287 | ? 'my $tail = do { no warnings; +{ @{$orig}[%d .. $#$orig]} };' | ||||
| 288 | : 'my $tail = [ @{$orig}[%d .. $#$orig] ];' | ||||
| 289 | ), | ||||
| 290 | $size, | ||||
| 291 | ); | ||||
| 292 | push @code, | ||||
| 293 | $slurpy->has_coercion | ||||
| 294 | ? sprintf( | ||||
| 295 | '$tail = %s;', | ||||
| 296 | $slurpy->coercion->inline_coercion( '$tail' ) | ||||
| 297 | ) | ||||
| 298 | : q(); | ||||
| 299 | push @code, sprintf( | ||||
| 300 | '(%s) ? push(@new, %s$tail) : ($return_orig++);', | ||||
| 301 | $slurpy->inline_check( '$tail' ), | ||||
| 302 | ( $slurpy_is_hashref ? '%' : '@' ), | ||||
| 303 | ); | ||||
| 304 | push @code, '}'; | ||||
| 305 | } #/ if ( $slurpy ) | ||||
| 306 | push @code, '}'; | ||||
| 307 | push @code, '$return_orig ? $orig : \\@new'; | ||||
| 308 | push @code, '}'; | ||||
| 309 | "@code"; | ||||
| 310 | } | ||||
| 311 | ); | ||||
| 312 | } #/ if ( $all_inlinable ) | ||||
| 313 | |||||
| 314 | else { | ||||
| 315 | my @is_optional = map !!$_->is_strictly_a_type_of( $_Optional ), @tuple; | ||||
| 316 | |||||
| 317 | $C->add_type_coercions( | ||||
| 318 | $parent => sub { | ||||
| 319 | my $value = @_ ? $_[0] : $_; | ||||
| 320 | |||||
| 321 | if ( !$slurpy and @$value > @tuple ) { | ||||
| 322 | return $value; | ||||
| 323 | } | ||||
| 324 | |||||
| 325 | my @new; | ||||
| 326 | for my $i ( 0 .. $#tuple ) { | ||||
| 327 | return \@new if $i > $#$value and $is_optional[$i]; | ||||
| 328 | |||||
| 329 | my $ct = $tuple[$i]; | ||||
| 330 | my $x = $ct->has_coercion ? $ct->coerce( $value->[$i] ) : $value->[$i]; | ||||
| 331 | |||||
| 332 | return $value unless $ct->check( $x ); | ||||
| 333 | |||||
| 334 | $new[$i] = $x; | ||||
| 335 | } #/ for my $i ( 0 .. $#tuple) | ||||
| 336 | |||||
| 337 | if ( $slurpy and @$value > @tuple ) { | ||||
| 338 | 2 | 320µs | 2 | 47µs | # spent 28µs (9+19) within Types::Standard::Tuple::BEGIN@338 which was called:
# once (9µs+19µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 338 # spent 28µs making 1 call to Types::Standard::Tuple::BEGIN@338
# spent 19µs making 1 call to warnings::unimport |
| 339 | my $tmp = | ||||
| 340 | $slurpy_is_hashref | ||||
| 341 | ? { @{$value}[ @tuple .. $#$value ] } | ||||
| 342 | : [ @{$value}[ @tuple .. $#$value ] ]; | ||||
| 343 | $tmp = $slurpy->coerce( $tmp ) if $slurpy->has_coercion; | ||||
| 344 | $slurpy->check( $tmp ) | ||||
| 345 | ? push( @new, $slurpy_is_hashref ? %$tmp : @$tmp ) | ||||
| 346 | : return ( $value ); | ||||
| 347 | } #/ if ( $slurpy and @$value...) | ||||
| 348 | |||||
| 349 | return \@new; | ||||
| 350 | }, | ||||
| 351 | ); | ||||
| 352 | } #/ else [ if ( $all_inlinable ) ] | ||||
| 353 | |||||
| 354 | return $C; | ||||
| 355 | } #/ sub __coercion_generator | ||||
| 356 | |||||
| 357 | 1 | 4µs | 1; | ||
# spent 3µs within Types::Standard::Tuple::CORE:sort which was called 2 times, avg 2µs/call:
# 2 times (3µs+0s) by Types::Standard::Tuple::__constraint_generator at line 63, avg 2µs/call |