Subject: | Could be made faster |
The following benchmarks at about twice the speed of your current is_aos implementation, for a simple case of:
is_aos([1..10])
Here it is:
use 5.010001;
use strict;
use warnings;
use constant HAS_TYPES_STANDARD => !!eval(
"use Types::Standard 0.046; use Type::Tiny::XS 0.003; 1"
);
sub is_aos {
my ($data, $opts) = @_;
$opts //= {};
my $max = $opts->{max};
if (HAS_TYPES_STANDARD and not defined $max) {
state $cc = Types::Standard::ArrayRef
->of(Types::Standard::Value)
->compiled_check;
return $cc->($data);
}
return 0 unless ref($data) eq 'ARRAY';
for my $i (0..@$data-1) {
last if defined($max) && $i >= $max;
return 0 if ref($data->[$i]);
}
1;
}