Skip to content

Commit

Permalink
- Array.ft(from, to) will now unpack the arguments into native Perl n…
Browse files Browse the repository at this point in the history
…umbers, reducing considerably the time spend inside the method.
  • Loading branch information
trizen committed Dec 20, 2015
1 parent 203ce65 commit 3a127a8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/Sidef/Types/Array/Array.pm
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,10 @@ package Sidef::Types::Array::Array {
return $self->last_by($arg);
}

my $from = @{$self} - $arg->get_value;
my $from = @{$self} - do {
local $Sidef::Types::Number::Number::GET_PERL_VALUE = 1;
$arg->get_value;
};
return $self->new(@{$self}[($from < 0 ? 0 : $from) .. $#{$self}]);
}

Expand Down Expand Up @@ -614,8 +617,11 @@ package Sidef::Types::Array::Array {

my $max = @{$self};

$from = defined($from) ? ($from->get_value) : 0;
$to = defined($to) ? ($to->get_value) : $max - 1;
{
local $Sidef::Types::Number::Number::GET_PERL_VALUE = 1;
$from = defined($from) ? ($from->get_value) : 0;
$to = defined($to) ? ($to->get_value) : $max - 1;
}

if (abs($from) > $max) {
return;
Expand Down Expand Up @@ -699,8 +705,7 @@ package Sidef::Types::Array::Array {
$n = $n->get_value;
}

my $end = @{$self};
foreach my $i ($n - 1 .. $end - 1) {
foreach my $i ($n - 1 .. $#{$self}) {
if (defined(my $res = $code->_run_code($self->new(@{$self}[$i - $n + 1 .. $i])))) {
return $res;
}
Expand Down

0 comments on commit 3a127a8

Please sign in to comment.