Skip to content

Commit 740457e

Browse files
committed
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 microsoft#15384.
1 parent 177ae3f commit 740457e

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/vs/workbench/services/search/node/textSearch.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
166166

167167
const outer = this;
168168

169-
function decodeBuffer(buffer: NodeBuffer): string {
169+
function decodeBuffer(buffer: NodeBuffer, start: number, end: number): string {
170170
if (options.encoding === UTF8 || options.encoding === UTF8_with_bom) {
171-
return buffer.toString(); // much faster to use built in toString() when encoding is default
171+
return buffer.toString(undefined, start, end); // much faster to use built in toString() when encoding is default
172172
}
173173

174-
return decode(buffer, options.encoding);
174+
return decode(buffer.slice(start, end), options.encoding);
175175
}
176176

177177
function lineFinished(offset: number): void {
178-
line += decodeBuffer(buffer.slice(pos, i + offset));
178+
line += decodeBuffer(buffer, pos, i + offset);
179179
perLineCallback(line, lineNumber);
180180
line = '';
181181
lineNumber++;
@@ -245,7 +245,7 @@ export class Engine implements ISearchEngine<ISerializedFileMatch> {
245245
}
246246
}
247247

248-
line += decodeBuffer(buffer.slice(pos, bytesRead));
248+
line += decodeBuffer(buffer, pos, bytesRead);
249249

250250
readFile(false /* isFirstRead */, clb); // Continue reading
251251
});

0 commit comments

Comments
 (0)