java-topology/defects/thunderbird-0002/patch/thunderbird-0002_nsMsgCopyService_DoNextCopy_ContainsObject_ON2.patch

42 lines
1.4 KiB
Diff

# UNDF: UNDF-2026-000000888
--- a/mailnews/base/src/nsMsgCopyService.cpp
+++ b/mailnews/base/src/nsMsgCopyService.cpp
@@ -description
# Defect: thunderbird-0002
# Component: mailnews/base/src/nsMsgCopyService.cpp
# Function: DoNextCopy()
# Pattern: ContainsObject() inside loop = O(N^2)
# Severity: MEDIUM-HIGH
# Measured: 250x overhead at N=500 copy requests
#
# DoNextCopy() iterates through m_copyRequests and for each request checks
# if the destination folder is already in activeTargets using
# ContainsObject(), which performs a linear scan. As activeTargets grows
# with each iteration, this creates O(N^2) complexity.
#
# This is exercised during bulk message operations (move/copy to folder),
# which are common email workflow operations. Moving 500+ messages between
# folders triggers this hot path.
#
# Before (O(N^2)):
# for (i = 0; i < cnt; i++) {
# copyRequest = m_copyRequests.ElementAt(i);
# if (activeTargets.ContainsObject(copyRequest->m_dstFolder)) {
# copyRequest = nullptr;
# continue;
# }
# ...
# activeTargets.AppendObject(copyRequest->m_dstFolder);
# }
#
# After (O(N)):
# nsTHashSet<nsIMsgFolder*> activeTargetSet;
# for (i = 0; i < cnt; i++) {
# copyRequest = m_copyRequests.ElementAt(i);
# if (activeTargetSet.Contains(copyRequest->m_dstFolder)) {
# copyRequest = nullptr;
# continue;
# }
# ...
# activeTargetSet.Insert(copyRequest->m_dstFolder);
# }