提交 0f7ac442 编写于 作者: R Rob Lourens

EH search - change frequent substr check to charCodeAt, seems like runtime...

EH search - change frequent substr check to charCodeAt, seems like runtime should optimize this anyway but this is faster
上级 a9d3a477
......@@ -136,8 +136,9 @@ export function rgErrorMsgForDisplay(msg: string): string | undefined {
export class RipgrepParser extends EventEmitter {
private static readonly RESULT_REGEX = /^\u001b\[0m(\d+)\u001b\[0m:(.*)(\r?)/;
private static readonly FILE_REGEX = /^\u001b\[0m(.+)\u001b\[0m$/;
private static readonly ESC_CODE = '\u001b'.charCodeAt(0);
private static readonly MATCH_START_CHAR = '\u001b';
// public for test
public static readonly MATCH_START_MARKER = '\u001b[0m\u001b[31m';
public static readonly MATCH_END_MARKER = '\u001b[0m';
......@@ -238,37 +239,44 @@ export class RipgrepParser extends EventEmitter {
const lineMatches: vscode.Range[] = [];
for (let i = 0; i < lineText.length - (RipgrepParser.MATCH_END_MARKER.length - 1);) {
if (lineText.substr(i, RipgrepParser.MATCH_START_MARKER.length) === RipgrepParser.MATCH_START_MARKER) {
// Match start
const chunk = lineText.slice(lastMatchEndPos, i);
realTextParts.push(chunk);
i += RipgrepParser.MATCH_START_MARKER.length;
matchTextStartPos = i;
matchTextStartRealIdx = textRealIdx;
} else if (lineText.substr(i, RipgrepParser.MATCH_END_MARKER.length) === RipgrepParser.MATCH_END_MARKER) {
// Match end
const chunk = lineText.slice(matchTextStartPos, i);
realTextParts.push(chunk);
if (!hitLimit) {
const startCol = matchTextStartRealIdx;
const endCol = textRealIdx;
// actually have to finish parsing the line, and use the real ones
lineMatches.push(new vscode.Range(lineNum, startCol, lineNum, endCol));
}
if (lineText.charCodeAt(i) === RipgrepParser.ESC_CODE) {
if (lineText.substr(i, RipgrepParser.MATCH_START_MARKER.length) === RipgrepParser.MATCH_START_MARKER) {
// Match start
const chunk = lineText.slice(lastMatchEndPos, i);
realTextParts.push(chunk);
i += RipgrepParser.MATCH_START_MARKER.length;
matchTextStartPos = i;
matchTextStartRealIdx = textRealIdx;
} else if (lineText.substr(i, RipgrepParser.MATCH_END_MARKER.length) === RipgrepParser.MATCH_END_MARKER) {
// Match end
const chunk = lineText.slice(matchTextStartPos, i);
realTextParts.push(chunk);
if (!hitLimit) {
const startCol = matchTextStartRealIdx;
const endCol = textRealIdx;
// actually have to finish parsing the line, and use the real ones
lineMatches.push(new vscode.Range(lineNum, startCol, lineNum, endCol));
}
matchTextStartPos = -1;
matchTextStartRealIdx = -1;
i += RipgrepParser.MATCH_END_MARKER.length;
lastMatchEndPos = i;
this.numResults++;
matchTextStartPos = -1;
matchTextStartRealIdx = -1;
i += RipgrepParser.MATCH_END_MARKER.length;
lastMatchEndPos = i;
this.numResults++;
// Check hit maxResults limit
if (this.numResults >= this.maxResults) {
// Finish the line, then report the result below
hitLimit = true;
// Check hit maxResults limit
if (this.numResults >= this.maxResults) {
// Finish the line, then report the result below
hitLimit = true;
}
} else {
// ESC char in file
i++;
textRealIdx++;
}
} else {
// Some other char
i++;
textRealIdx++;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册