Skip to content

Commit

Permalink
Indices _calc_abc_dispatcher: reorder some logic, use an empty array …
Browse files Browse the repository at this point in the history
…state var

Minor optimisation but avoids sub call costs.

The state var should be rarely needed but we might
as well not create a new one every time.
  • Loading branch information
shawnlaffan committed Feb 28, 2024
1 parent cac1d78 commit 1666094
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/Biodiverse/Indices/Indices.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1813,20 +1813,22 @@ sub _calc_abc_dispatcher {
// $args{label_list2}
);

state $empty_array = [];

return $self->_calc_abc_pairwise_mode(%args)
if $self->get_pairwise_mode
&& @{$args{element_list1} // []} == 1
&& @{$args{element_list2} // []} == 1
&& !$have_lb_lists;
if @{$args{element_list1} // $empty_array} == 1
&& @{$args{element_list2} // $empty_array} == 1
&& $self->get_pairwise_mode
&& !$have_lb_lists;

return $self->_calc_abc_hierarchical_mode(%args)
if $args{current_node_details}
&& !$have_lb_lists
&& $self->get_hierarchical_mode;
&& !$have_lb_lists
&& $self->get_hierarchical_mode;

return $self->_calc_abc(%args)
if is_hashref($args{element_list1})
|| @{$args{element_list1} // []} != 1
|| @{$args{element_list1} // $empty_array} != 1
|| defined $args{element_list2}
|| $have_lb_lists;

Expand Down

0 comments on commit 1666094

Please sign in to comment.