From 99aba7475f0a558c8bd82230178c4574d1a8fea1 Mon Sep 17 00:00:00 2001 From: Yuki Matsuzawa Date: Sat, 29 Aug 2026 09:03:57 +0900 Subject: [PATCH] Optimize spectrum peak shrinking Replace repeated LINQ enumeration with a constant-time count check in the MS2 matching hot path. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/Common/CommonStandard/Algorithm/Scoring/Ms2ScanMatching.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Common/CommonStandard/Algorithm/Scoring/Ms2ScanMatching.cs b/src/Common/CommonStandard/Algorithm/Scoring/Ms2ScanMatching.cs index b4f522cee..134fdceae 100644 --- a/src/Common/CommonStandard/Algorithm/Scoring/Ms2ScanMatching.cs +++ b/src/Common/CommonStandard/Algorithm/Scoring/Ms2ScanMatching.cs @@ -44,7 +44,7 @@ public MatchedSpectrumPair GetMatchedSpectrum(List experiment, Lis private List ShrinkPeaks(List reference) { var result = new List(reference.Count); foreach (var peak in reference) { - if (result.Any() && peak.Mass - result[result.Count - 1].Mass <= _searchParameter.Ms2Tolerance) { + if (result.Count > 0 && peak.Mass - result[result.Count - 1].Mass <= _searchParameter.Ms2Tolerance) { result[result.Count - 1].Intensity += peak.Intensity; result[result.Count - 1].SpectrumComment |= peak.SpectrumComment; if (string.IsNullOrEmpty(result[result.Count - 1].Comment)) {