mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-18 05:57:40 +02:00
perf(gateguard): profile a change only when used and check its window first
This commit is contained in:
@@ -708,12 +708,13 @@ function trivialInFile(pairs, fileText, spec) {
|
||||
const start = windowStart(text, found.first);
|
||||
const end = windowEnd(text, found.last + oldString.length);
|
||||
work += start + 2 * (end - start);
|
||||
if (end - start > MAX_WINDOW_CHARS || work > MAX_CONTEXT_WORK || !spec.startsFresh(text.slice(0, start), spec)) return false;
|
||||
if (end - start > MAX_WINDOW_CHARS || work > MAX_CONTEXT_WORK) return false;
|
||||
const before = text.slice(start, end);
|
||||
const after = replaceAll
|
||||
? before.split(oldString).join(newString)
|
||||
: `${text.slice(start, found.first)}${newString}${text.slice(found.first + oldString.length, end)}`;
|
||||
if (!isTrivialEdit(before, after, spec)) return false;
|
||||
// see docs/gateguard/change-profile.md#file-context
|
||||
if (!isTrivialEdit(before, after, spec) || !spec.startsFresh(text.slice(0, start), spec)) return false;
|
||||
text = `${text.slice(0, start)}${after}${text.slice(end)}`;
|
||||
if (text.length > MAX_FILE_CHARS) return false;
|
||||
}
|
||||
|
||||
@@ -193,6 +193,11 @@ function codeQuestionIds(isWrite, profile) {
|
||||
}
|
||||
|
||||
/** Stable ids of the first-touch questions for a class, action and change profile. */
|
||||
/** True when a class's questions depend on the change profile. */
|
||||
function questionsUseProfile(cls) {
|
||||
return !Object.hasOwn(CLASS_QUESTION_IDS, cls);
|
||||
}
|
||||
|
||||
function questionIdsFor(cls, isWrite, profile) {
|
||||
const ids = Object.hasOwn(CLASS_QUESTION_IDS, cls) ? CLASS_QUESTION_IDS[cls](Boolean(isWrite)) : codeQuestionIds(Boolean(isWrite), profile);
|
||||
return [...ids, 'quote-instruction'];
|
||||
@@ -407,6 +412,7 @@ function collapseGateDir(filePath, data, cls) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
questionsUseProfile,
|
||||
WINDOWS_PATH_PATTERN,
|
||||
COLLAPSIBLE_CLASSES,
|
||||
CLASS_QUESTIONS,
|
||||
|
||||
Reference in New Issue
Block a user