Skip to content

Commit

Permalink
BaseData.pm: use pairmap instead of pairs
Browse files Browse the repository at this point in the history
Gives a slight speedup.

Ultimately we will replace these calls with
n-at-a-time for loops but that requires a
minimum perl version of 5.36.
  • Loading branch information
shawnlaffan committed Feb 13, 2024
1 parent 816bbc4 commit 3184526
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/Biodiverse/BaseData.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Carp;
#use Data::Dumper;
use POSIX qw {fmod floor};
use Scalar::Util qw /looks_like_number blessed/;
use List::Util 1.45 qw /max min sum pairs uniq/;
use List::Util 1.45 qw /max min sum pairs uniq pairmap/;
use List::MoreUtils qw /first_index/;
use Path::Tiny qw /path/;
use Geo::Converter::dms2dd qw {dms2dd};
Expand Down Expand Up @@ -1380,10 +1380,7 @@ sub add_elements_collated_simple_aa {
$self->add_element_simple_aa(undef, $gp, 0, $csv_object);
}
else {
foreach my $lb_count_pair (pairs %$lb_hash) {
my ($lb, $count) = @$lb_count_pair;
$self->add_element_simple_aa($lb, $gp, $count, $csv_object);
}
pairmap {$self->add_element_simple_aa($a, $gp, $b, $csv_object)} %$lb_hash;
}
}
}
Expand All @@ -1395,10 +1392,7 @@ sub add_elements_collated_simple_aa {
$self->add_element_simple_aa($lb, undef, 0, $csv_object);
}
else {
foreach my $gp_count_pair (pairs %$gp_hash) {
my ($gp, $count) = @$gp_count_pair;
$self->add_element_simple_aa($lb, $gp, $count, $csv_object);
}
pairmap {$self->add_element_simple_aa($lb, $a, $b, $csv_object)} %$gp_hash;
}
}
}
Expand Down

0 comments on commit 3184526

Please sign in to comment.