diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp index 6b332d4e5b0b976074462ae975f5aca0bad9435a..dcbf38ed7bc5fe644a0d38327c180c5af4d2020f 100644 --- a/src/core/identificationgroup.cpp +++ b/src/core/identificationgroup.cpp @@ -54,11 +54,19 @@ ProteinMatch * IdentificationGroup::getProteinMatch(const QString accession) { if (accession.isEmpty()) { throw pappso::PappsoException(QObject::tr("Error protein match not found : accession is empty")); } - for (ProteinMatch * p_protein_match : _protein_match_list) { - if (p_protein_match->getProteinXtpSp().get()->getAccession() == accession) { - return p_protein_match; + auto it_cache = _cache_accession_protein_match.find(accession); + if (it_cache == _cache_accession_protein_match.end()) { + //accession not found in cache + for (ProteinMatch * p_protein_match : _protein_match_list) { + if (p_protein_match->getProteinXtpSp().get()->getAccession() == accession) { + _cache_accession_protein_match.insert(std::pair<QString, ProteinMatch *>(accession, p_protein_match)); + return p_protein_match; + } } } + else { + return it_cache->second; + } return nullptr; } void IdentificationGroup::addProteinMatch(ProteinMatch * protein_match) { @@ -66,20 +74,13 @@ void IdentificationGroup::addProteinMatch(ProteinMatch * protein_match) { if (accession.isEmpty()) { throw pappso::PappsoException(QObject::tr("Error adding protein match : accession is empty")); } - bool push = true; - for (ProteinMatch * p_protein_match : _protein_match_list) { - if (p_protein_match == protein_match) { - push = false; - } - else { - if(p_protein_match->getProteinXtpSp().get()->getAccession() == accession) { - throw pappso::PappsoException(QObject::tr("Error adding protein match : accession %1 already registered").arg(accession)); - } - } - } - if (push) { + auto it_cache = _cache_already_added_protein_match.find(protein_match); + if (it_cache == _cache_already_added_protein_match.end()) { + //accession not found in cache + _cache_already_added_protein_match.insert(protein_match); _protein_match_list.push_back(protein_match); } + } bool IdentificationGroup::contains (const MsRun * p_msrun) const { diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h index e71793757f146034a957806aec52cf5d3a4eb058..279b7a8b7d85bdfe1210c547fb5c2debf42e5615 100644 --- a/src/core/identificationgroup.h +++ b/src/core/identificationgroup.h @@ -31,6 +31,7 @@ #ifndef IDENTIFICATIONGROUP_H #define IDENTIFICATIONGROUP_H +#include <set> class Project; @@ -92,6 +93,9 @@ private : std::vector<ProteinMatch *> _protein_match_list; std::vector<MsRunSp> _ms_run_list; + + std::map<QString, ProteinMatch *> _cache_accession_protein_match; + std::set<ProteinMatch *> _cache_already_added_protein_match; }; #endif // IDENTIFICATIONGROUP_H