Browse Source

Fixes excessive memory usages with diff regex

main
Eric Amodio 7 years ago
parent
commit
dd0b95498e
1 changed files with 11 additions and 4 deletions
  1. +11
    -4
      src/git/parsers/diffParser.ts

+ 11
- 4
src/git/parsers/diffParser.ts View File

@ -12,15 +12,22 @@ export class GitDiffParser {
const chunks: GitDiffChunk[] = [];
let match: RegExpExecArray | null = null;
let chunk: string;
let currentStart: number;
let previousStart: number;
do {
match = unifiedDiffRegex.exec(`${data}\n@@`);
if (match == null) break;
const previousStart = +match[1];
const currentStart = +match[3];
// Stops excessive memory usage
// https://bugs.chromium.org/p/v8/issues/detail?id=2869
chunk = (' ' + match[5]).substr(1);
currentStart = parseInt(match[3], 10);
previousStart = parseInt(match[1], 10);
const chunk = match[5];
chunks.push(new GitDiffChunk(chunk, { start: currentStart, end: currentStart + +match[4] }, { start: previousStart, end: previousStart + +match[2] }));
chunks.push(new GitDiffChunk(chunk, { start: currentStart, end: currentStart + parseInt(match[4], 10) }, { start: previousStart, end: previousStart + parseInt(match[2], 10) }));
} while (match != null);
if (!chunks.length) return undefined;

Loading…
Cancel
Save