Skip to content

Commit dd0b954

Browse files
committed
Fixes excessive memory usages with diff regex
1 parent e631640 commit dd0b954

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/git/parsers/diffParser.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@ export class GitDiffParser {
1212
const chunks: GitDiffChunk[] = [];
1313

1414
let match: RegExpExecArray | null = null;
15+
16+
let chunk: string;
17+
let currentStart: number;
18+
let previousStart: number;
19+
1520
do {
1621
match = unifiedDiffRegex.exec(`${data}\n@@`);
1722
if (match == null) break;
1823

19-
const previousStart = +match[1];
20-
const currentStart = +match[3];
24+
// Stops excessive memory usage
25+
// https://bugs.chromium.org/p/v8/issues/detail?id=2869
26+
chunk = (' ' + match[5]).substr(1);
27+
currentStart = parseInt(match[3], 10);
28+
previousStart = parseInt(match[1], 10);
2129

22-
const chunk = match[5];
23-
chunks.push(new GitDiffChunk(chunk, { start: currentStart, end: currentStart + +match[4] }, { start: previousStart, end: previousStart + +match[2] }));
30+
chunks.push(new GitDiffChunk(chunk, { start: currentStart, end: currentStart + parseInt(match[4], 10) }, { start: previousStart, end: previousStart + parseInt(match[2], 10) }));
2431
} while (match != null);
2532

2633
if (!chunks.length) return undefined;

0 commit comments

Comments
 (0)