提交 2cbcd647 编写于 作者: R Rob Lourens

Text search perf improvement for long lines/multiline results

上级 d208a877
......@@ -162,29 +162,41 @@ export class RipgrepParser extends EventEmitter {
}
public handleData(data: Buffer | string): void {
if (this.isDone) {
return;
}
const dataStr = typeof data === 'string' ? data : this.stringDecoder.write(data);
this.handleDecodedData(dataStr);
}
private handleDecodedData(decodedData: string): void {
// check for newline before appending to remainder
let newlineIdx = decodedData.indexOf('\n');
// If the previous data chunk didn't end in a newline, prepend it to this chunk
const dataStr = this.remainder ?
this.remainder + decodedData :
decodedData;
const dataStr = this.remainder + decodedData;
const dataLines: string[] = dataStr.split(/\r\n|\n/);
this.remainder = dataLines[dataLines.length - 1] ? <string>dataLines.pop() : '';
if (newlineIdx >= 0) {
newlineIdx += this.remainder.length;
} else {
// Shortcut
this.remainder = dataStr;
return;
}
for (let l = 0; l < dataLines.length; l++) {
const line = dataLines[l];
if (line) { // Empty line at the end of each chunk
this.handleLine(line);
}
let prevIdx = 0;
while (newlineIdx >= 0) {
this.handleLine(dataStr.substring(prevIdx, newlineIdx).trim());
prevIdx = newlineIdx + 1;
newlineIdx = dataStr.indexOf('\n', prevIdx);
}
this.remainder = dataStr.substring(prevIdx).trim();
}
private handleLine(outputLine: string): void {
if (this.isDone) {
if (this.isDone || !outputLine) {
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册