Skip to content

Commit 5b030f2

Browse files
committed
perf(shared): strip plan prefixes in linear time
1 parent 7195b69 commit 5b030f2

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎packages/shared/src/proposedPlanText.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ export function proposedPlanTitle(planMarkdown: string): string | null {
55

66
export function stripDisplayedPlanMarkdown(planMarkdown: string): string {
77
const lines = planMarkdown.trimEnd().split(/\r?\n/);
8-
const sourceLines = lines[0] && /^\s{0,3}#{1,6}\s+/.test(lines[0]) ? lines.slice(1) : [...lines];
9-
while (sourceLines[0]?.trim().length === 0) {
10-
sourceLines.shift();
8+
let start = lines[0] && /^\s{0,3}#{1,6}\s+/.test(lines[0]) ? 1 : 0;
9+
while (lines[start]?.trim().length === 0) {
10+
start += 1;
1111
}
12-
const firstHeadingMatch = sourceLines[0]?.match(/^\s{0,3}#{1,6}\s+(.+)$/);
12+
const firstHeadingMatch = lines[start]?.match(/^\s{0,3}#{1,6}\s+(.+)$/);
1313
if (firstHeadingMatch?.[1]?.trim().toLowerCase() === "summary") {
14-
sourceLines.shift();
15-
while (sourceLines[0]?.trim().length === 0) {
16-
sourceLines.shift();
14+
start += 1;
15+
while (lines[start]?.trim().length === 0) {
16+
start += 1;
1717
}
1818
}
19-
return sourceLines.join("\n");
19+
return lines.slice(start).join("\n");
2020
}

0 commit comments

Comments
 (0)