From 608b504b591e5409e26a1dc29469ade7ec9a0ea5 Mon Sep 17 00:00:00 2001 From: jonathonl Date: Sun, 3 Dec 2023 13:44:27 -0500 Subject: [PATCH] Improves performance of remove_eov(). --- src/unique_haplotype.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/unique_haplotype.cpp b/src/unique_haplotype.cpp index f7cca4a..a62f7df 100644 --- a/src/unique_haplotype.cpp +++ b/src/unique_haplotype.cpp @@ -282,13 +282,19 @@ int unique_haplotype_block::deserialize(savvy::reader& input_file, savvy::varian void unique_haplotype_block::remove_eov() { - for (auto it = unique_map_.begin(); it != unique_map_.end(); ) + std::size_t eov_cnt = 0; + auto it = unique_map_.begin(); + auto dest_it = it; + for ( ; it != unique_map_.end(); ++it) { if (savvy::typed_value::is_end_of_vector(*it)) - it = unique_map_.erase(it); + ++eov_cnt; else - ++it; + *(dest_it++) = *it; } + + if (eov_cnt) + unique_map_.resize(unique_map_.size() - eov_cnt); } bool unique_haplotype_block::deserialize(std::istream& is, int m3vcf_version, std::size_t n_haplotypes) @@ -547,4 +553,4 @@ float reduced_haplotypes::compression_ratio() const } return num / denom; -} \ No newline at end of file +}