Skip to content

Commit

Permalink
get_element_name_as_array_aa: return the stored array
Browse files Browse the repository at this point in the history
It was returning the package cache value.
This is the same array but we might as well
avoid the cache lookup.
  • Loading branch information
shawnlaffan committed Feb 13, 2024
1 parent 50f5ab5 commit 22a6e83
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/Biodiverse/BaseStruct.pm
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,17 @@ sub get_element_hash {
sub get_element_name_as_array_aa {
my ($self, $element, $csv_object) = @_;

# caching saves a little time for large data sets
# but needs to be shared with a "parent" object to make a difference
# e.g. a spatial object copies from a groups object
my $arr = $self->{ELEMENTS}{$element}{_ELEMENT_ARRAY};
return wantarray ? @$arr : $arr
if $arr;

state $el_list_ref_cache_name = '_ELEMENT_ARRAY_REF_CACHE';
my $element_list_ref_cache = $self->get_cached_value_dor_set_default_href ($el_list_ref_cache_name);

$self->{ELEMENTS}{$element}{_ELEMENT_ARRAY} = $element_list_ref_cache->{$element};
$arr = $self->{ELEMENTS}{$element}{_ELEMENT_ARRAY} = $element_list_ref_cache->{$element};

return wantarray
? @{$element_list_ref_cache->{$element}}
: $element_list_ref_cache->{$element}
if $element_list_ref_cache->{$element};
return wantarray ? @$arr : $arr
if $arr;

# package level cache
state $_el_array_cache = {};
Expand Down

0 comments on commit 22a6e83

Please sign in to comment.