Optimized parsers for speed & memory usage

Switches to lazy parsing of diff chunks
This commit is contained in:
Eric Amodio
2017-06-10 00:16:46 -04:00
parent eeff31cf27
commit e6316400f0
16 changed files with 343 additions and 340 deletions

View File

@@ -1,16 +1,17 @@
'use strict';
import { GitAuthor, GitCommit, GitCommitLine } from './commit';
import { GitAuthor, GitCommitLine } from './commit';
import { GitBlameCommit } from './blameCommit';
export interface GitBlame {
repoPath: string;
authors: Map<string, GitAuthor>;
commits: Map<string, GitCommit>;
commits: Map<string, GitBlameCommit>;
lines: GitCommitLine[];
}
export interface GitBlameLine {
author: GitAuthor;
commit: GitCommit;
commit: GitBlameCommit;
line: GitCommitLine;
}
@@ -20,6 +21,6 @@ export interface GitBlameLines extends GitBlame {
export interface GitBlameCommitLines {
author: GitAuthor;
commit: GitCommit;
commit: GitBlameCommit;
lines: GitCommitLine[];
}

View File

@@ -0,0 +1,20 @@
'use strict';
import { GitCommit, GitCommitLine } from './commit';
export class GitBlameCommit extends GitCommit {
constructor(
repoPath: string,
sha: string,
fileName: string,
author: string,
date: Date,
message: string,
public lines: GitCommitLine[],
originalFileName?: string,
previousSha?: string,
previousFileName?: string
) {
super('blame', repoPath, sha, fileName, author, date, message, originalFileName, previousSha, previousFileName);
}
}

View File

@@ -21,7 +21,7 @@ export type GitCommitType = 'blame' | 'branch' | 'file' | 'stash';
export class GitCommit {
type: GitCommitType;
lines: GitCommitLine[];
// lines: GitCommitLine[];
originalFileName?: string;
previousSha?: string;
previousFileName?: string;
@@ -36,7 +36,7 @@ export class GitCommit {
public author: string,
public date: Date,
public message: string,
lines?: GitCommitLine[],
// lines?: GitCommitLine[],
originalFileName?: string,
previousSha?: string,
previousFileName?: string
@@ -44,7 +44,7 @@ export class GitCommit {
this.type = type;
this.fileName = this.fileName && this.fileName.replace(/, ?$/, '');
this.lines = lines || [];
// this.lines = lines || [];
this.originalFileName = originalFileName;
this.previousSha = previousSha;
this.previousFileName = previousFileName;

View File

@@ -1,20 +1,41 @@
'use strict';
import { GitDiffParser } from '../parsers/diffParser';
export interface GitDiffLine {
line: string;
state: 'added' | 'removed' | 'unchanged';
}
export interface GitDiffChunk {
current: (GitDiffLine | undefined)[];
currentStart: number;
currentEnd: number;
export class GitDiffChunk {
previous: (GitDiffLine | undefined)[];
previousStart: number;
previousEnd: number;
private _chunk: string | undefined;
private _current: (GitDiffLine | undefined)[] | undefined;
private _previous: (GitDiffLine | undefined)[] | undefined;
chunk?: string;
constructor(chunk: string, public currentPosition: { start: number, end: number }, public previousPosition: { start: number, end: number }) {
this._chunk = chunk;
}
get current(): (GitDiffLine | undefined)[] {
if (this._chunk !== undefined) {
this.parseChunk();
}
return this._current!;
}
get previous(): (GitDiffLine | undefined)[] {
if (this._chunk !== undefined) {
this.parseChunk();
}
return this._previous!;
}
private parseChunk() {
[this._current, this._previous] = GitDiffParser.parseChunk(this._chunk!);
this._chunk = undefined;
}
}
export interface GitDiff {

View File

@@ -1,6 +1,6 @@
'use strict';
import { Uri } from 'vscode';
import { GitCommit, GitCommitLine, GitCommitType } from './commit';
import { GitCommit, GitCommitType } from './commit';
import { GitStatusFileStatus, IGitStatusFile } from './status';
import * as path from 'path';
@@ -23,12 +23,11 @@ export class GitLogCommit extends GitCommit {
message: string,
status?: GitStatusFileStatus,
fileStatuses?: IGitStatusFile[],
lines?: GitCommitLine[],
originalFileName?: string,
previousSha?: string,
previousFileName?: string
) {
super(type, repoPath, sha, fileName, author, date, message, lines, originalFileName, previousSha, previousFileName);
super(type, repoPath, sha, fileName, author, date, message, originalFileName, previousSha, previousFileName);
this.fileNames = this.fileName;

View File

@@ -1,5 +1,6 @@
'use strict';
export * from './blame';
export * from './blameCommit';
export * from './branch';
export * from './commit';
export * from './diff';

View File

@@ -1,5 +1,4 @@
'use strict';
import { GitCommitLine } from './commit';
import { GitLogCommit } from './logCommit';
import { GitStatusFileStatus, IGitStatusFile } from './status';
@@ -14,12 +13,11 @@ export class GitStashCommit extends GitLogCommit {
message: string,
status?: GitStatusFileStatus,
fileStatuses?: IGitStatusFile[],
lines?: GitCommitLine[],
originalFileName?: string,
previousSha?: string,
previousFileName?: string
) {
super('stash', repoPath, sha, fileName, 'You', date, message, status, fileStatuses, lines, originalFileName, previousSha, previousFileName);
super('stash', repoPath, sha, fileName, 'You', date, message, status, fileStatuses, originalFileName, previousSha, previousFileName);
}
get shortSha() {