提交 740457e8 编写于 作者: R roblou

Replace buffer.slice in text search with buffer.toString(undefined, start, end).

This is much faster although it's not totally obvious why. But it's run for every line of every file in the workspace so it's very sensitive.  See #15384.
上级 177ae3f1
......@@ -166,16 +166,16 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
const outer = this;
function decodeBuffer(buffer: NodeBuffer): string {
function decodeBuffer(buffer: NodeBuffer, start: number, end: number): string {
if (options.encoding === UTF8 || options.encoding === UTF8_with_bom) {
return buffer.toString(); // much faster to use built in toString() when encoding is default
return buffer.toString(undefined, start, end); // much faster to use built in toString() when encoding is default
}
return decode(buffer, options.encoding);
return decode(buffer.slice(start, end), options.encoding);
}
function lineFinished(offset: number): void {
line += decodeBuffer(buffer.slice(pos, i + offset));
line += decodeBuffer(buffer, pos, i + offset);
perLineCallback(line, lineNumber);
line = '';
lineNumber++;
......@@ -245,7 +245,7 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
}
}
line += decodeBuffer(buffer.slice(pos, bytesRead));
line += decodeBuffer(buffer, pos, bytesRead);
readFile(false /* isFirstRead */, clb); // Continue reading
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册