From eb4dfd07d0fc23e4b814c78f288a4fcf82b39b6b Mon Sep 17 00:00:00 2001 From: Ben Haller Date: Sun, 6 Oct 2024 10:44:31 -0400 Subject: [PATCH] remove cached_parent_haplosomes_value_ --- core/population.cpp | 1 - core/species_eidos.cpp | 11 +++-------- core/subpopulation.cpp | 42 ++++++------------------------------------ core/subpopulation.h | 5 ++--- 4 files changed, 11 insertions(+), 48 deletions(-) diff --git a/core/population.cpp b/core/population.cpp index b58e17dc..2f4d1822 100644 --- a/core/population.cpp +++ b/core/population.cpp @@ -477,7 +477,6 @@ void Population::ResolveSurvivalPhaseMovement(void) subpop->parent_haplosomes_.resize((size_t)subpop->parent_subpop_size_ * 2); subpop->parent_individuals_.resize(subpop->parent_subpop_size_); - subpop->cached_parent_haplosomes_value_.reset(); subpop->cached_parent_individuals_value_.reset(); } } diff --git a/core/species_eidos.cpp b/core/species_eidos.cpp index 6471a0af..5896964e 100644 --- a/core/species_eidos.cpp +++ b/core/species_eidos.cpp @@ -2374,17 +2374,12 @@ EidosValue_SP Species::ExecuteMethod_killIndividuals(EidosGlobalStringID p_metho if (killed_count) { - // First, clear our haplosome and individual caches in all subpopulations; any subpops involved in + // First, clear our individual caches in all subpopulations; any subpops involved in // this method would be invalidated anyway so this probably isn't even that much overkill in - // most models. Note that the child haplosomes/individuals caches don't need to be thrown away, + // most models. Note that the child individuals caches don't need to be thrown away, // because they aren't used in nonWF models and this is a nonWF-only method. for (auto subpop_pair : population_.subpops_) - { - Subpopulation *subpop = subpop_pair.second; - - subpop->cached_parent_haplosomes_value_.reset(); - subpop->cached_parent_individuals_value_.reset(); - } + subpop_pair.second->cached_parent_individuals_value_.reset(); // Invalidate interactions; we just do this for all subpops, for now, rather than trying to // selectively invalidate only the subpops involved in the deaths that occurred diff --git a/core/subpopulation.cpp b/core/subpopulation.cpp index dfe9328d..2b3a896c 100644 --- a/core/subpopulation.cpp +++ b/core/subpopulation.cpp @@ -262,7 +262,6 @@ void Subpopulation::GenerateParentsToFit(slim_age_t p_initial_age, double p_sex_ int32_t mutrun_count = chromosome.mutrun_count_; slim_position_t mutrun_length = chromosome.mutrun_length_; - cached_parent_haplosomes_value_.reset(); cached_parent_individuals_value_.reset(); if (parent_individuals_.size() || parent_haplosomes_.size()) @@ -3288,7 +3287,6 @@ void Subpopulation::SwapChildAndParentHaplosomes(void) // Execute the haplosome swap child_haplosomes_.swap(parent_haplosomes_); - cached_parent_haplosomes_value_.reset(); // Execute a swap of individuals as well; since individuals carry so little baggage, this is mostly important just for moving tag values child_individuals_.swap(parent_individuals_); @@ -3574,7 +3572,6 @@ void Subpopulation::MergeReproductionOffspring(void) // final cleanup parent_subpop_size_ += new_count; - cached_parent_haplosomes_value_.reset(); cached_parent_individuals_value_.reset(); nonWF_offspring_haplosomes_.clear(); @@ -3893,7 +3890,6 @@ void Subpopulation::ViabilitySurvival(std::vector &p_survival_c parent_haplosomes_.resize((size_t)parent_subpop_size_ * 2); parent_individuals_.resize(parent_subpop_size_); - cached_parent_haplosomes_value_.reset(); cached_parent_individuals_value_.reset(); } } @@ -3967,33 +3963,12 @@ EidosValue_SP Subpopulation::GetProperty(EidosGlobalStringID p_property_id) } case gID_haplosomes: { - if (!cached_parent_haplosomes_value_) - { - EidosValue_Object *vec = (new (gEidosValuePool->AllocateChunk()) EidosValue_Object(gSLiM_Haplosome_Class))->reserve(parent_haplosomes_.size()); - cached_parent_haplosomes_value_ = EidosValue_SP(vec); - - for (auto haplosome_iter : parent_haplosomes_) - vec->push_object_element_no_check_NORR(haplosome_iter); - } - -#if DEBUG - { - // check that the cache is correct - const EidosObject * const *vec_direct = cached_parent_haplosomes_value_->ObjectData(); - int vec_size = cached_parent_haplosomes_value_->Count(); - - if (vec_size == (int)parent_haplosomes_.size()) - { - for (int i = 0; i < vec_size; ++i) - if (vec_direct[i] != parent_haplosomes_[i]) - EIDOS_TERMINATION << "ERROR (Subpopulation::GetProperty): value mismatch in cached_parent_haplosomes_value_." << EidosTerminate(); - } - else - EIDOS_TERMINATION << "ERROR (Subpopulation::GetProperty): size mismatch in cached_parent_haplosomes_value_." << EidosTerminate(); - } -#endif + EidosValue_Object *vec = (new (gEidosValuePool->AllocateChunk()) EidosValue_Object(gSLiM_Haplosome_Class))->reserve(parent_haplosomes_.size()); - return cached_parent_haplosomes_value_; + for (auto haplosome_iter : parent_haplosomes_) + vec->push_object_element_no_check_NORR(haplosome_iter); + + return EidosValue_SP(vec); } case gID_haplosomesNonNull: { @@ -5789,12 +5764,7 @@ EidosValue_SP Subpopulation::ExecuteMethod_takeMigrants(EidosGlobalStringID p_me // most models. Note that the child haplosomes/individuals caches don't need to be thrown away, // because they aren't used in nonWF models and this is a nonWF-only method. for (auto subpop_pair : population_.subpops_) - { - Subpopulation *subpop = subpop_pair.second; - - subpop->cached_parent_haplosomes_value_.reset(); - subpop->cached_parent_individuals_value_.reset(); - } + subpop_pair.second->cached_parent_individuals_value_.reset(); // Invalidate interactions; we just do this for all subpops, for now, rather than trying to // selectively invalidate only the subpops involved in the migrations that occurred diff --git a/core/subpopulation.h b/core/subpopulation.h index 684a3c26..987a694a 100644 --- a/core/subpopulation.h +++ b/core/subpopulation.h @@ -131,12 +131,11 @@ class Subpopulation : public EidosDictionaryUnretained bool has_null_haplosomes_ = false; // false until a null haplosome is added; NOT set by null haplosomes for sex chromosome sims; use CouldContainNullHaplosomes() to check this flag std::vector parent_haplosomes_; // OWNED: all haplosomes in the parental generation; each individual gets two haplosomes, males are XY (not YX) - EidosValue_SP cached_parent_haplosomes_value_; // cached for the haplosomes property; reset() if changed slim_popsize_t parent_subpop_size_; // parental subpopulation size slim_popsize_t parent_first_male_index_ = INT_MAX; // the index of the first male in the parental Haplosome vector (NOT premultiplied by 2!); equal to the number of females std::vector parent_individuals_; // OWNED: objects representing simulated individuals, each of which has two haplosomes EidosValue_SP cached_parent_individuals_value_; // cached for the individuals property; self-maintains - double parent_sex_ratio_ = 0.0; // WF only: what sex ratio the parental haplosomes approximate (M:M+F) + double parent_sex_ratio_ = 0.0; // WF only: what sex ratio the parent individuals approximate (M:M+F) // WF only: // In WF models, we actually switch to a "child" generation just after offspring generation; this is then the active generation. @@ -146,7 +145,7 @@ class Subpopulation : public EidosDictionaryUnretained slim_popsize_t child_subpop_size_; // child subpopulation size slim_popsize_t child_first_male_index_ = INT_MAX; // the index of the first male in the child Haplosome vector (NOT premultiplied by 2!); equal to the number of females std::vector child_individuals_; // OWNED: objects representing simulated individuals, each of which has two haplosomes - double child_sex_ratio_ = 0.0; // what sex ratio the child haplosomes approximate (M:M+F) + double child_sex_ratio_ = 0.0; // what sex ratio the child individuals approximate (M:M+F) // nonWF only: // In nonWF models, we place generated offspring into a temporary holding pen, but it is never made the "active generation"