perf(config/findings): getOpenCodeHttpsAgent 改模組單例、normalizeText 加 memoization 快取

另含 comments.js bySeverity 改用預建 LEVEL_RANK Map(隨 fix commit 一併提交)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeffery
2026-06-26 15:26:08 +08:00
co-authored by Claude Opus 4.8
parent 402630fa69
commit 998b5ca5ac
2 changed files with 12 additions and 4 deletions
+7 -1
View File
@@ -107,14 +107,20 @@ function cleanText(value) {
* @param {*} value - 任意值;非字串會先經 cleanText 轉為空字串。
* @returns {string} 正規化後、以單一空白分隔的字串(可能為空字串)。
* @remarks 用於 finding 與排除條目文字的雙向「包含」比對(applyExclusions、appendExclusions)。
* 因為比對常對同一段文字重複呼叫(findings × exclusions 笛卡爾積),
* 以模組層級 Map 對「字串輸入」做 memoization,避免重複跑 NFKC/正則替換。
*/
const _normalizeTextCache = new Map();
export function normalizeText(value) {
return cleanText(value)
if (typeof value === 'string' && _normalizeTextCache.has(value)) return _normalizeTextCache.get(value);
const result = cleanText(value)
.normalize('NFKC')
.toLowerCase()
.replace(/[\p{P}\p{S}\s]+/gu, ' ')
.replace(/\s+/g, ' ')
.trim();
if (typeof value === 'string') _normalizeTextCache.set(value, result);
return result;
}
/**