提交 d1571770 编写于 作者: J Johannes Rieken

debt - remove BufferPool because allocUnsafe already uses pooling

上级 a36823fc
......@@ -44,30 +44,6 @@ import product from 'vs/platform/node/product';
import { IEncodingOverride, ResourceEncodings } from 'vs/workbench/services/files/electron-browser/encoding';
import { createReadableOfSnapshot } from 'vs/workbench/services/files/electron-browser/streams';
class BufferPool {
static _64K = new BufferPool(64 * 1024, 5);
constructor(
readonly bufferSize: number,
private readonly _capacity: number,
private readonly _free: Buffer[] = [],
) { }
acquire(): Buffer {
if (this._free.length === 0) {
return Buffer.allocUnsafe(this.bufferSize);
} else {
return this._free.shift();
}
}
release(buf: Buffer): void {
if (this._free.length <= this._capacity) {
this._free.push(buf);
}
}
}
export interface IFileServiceTestOptions {
disableWatcher?: boolean;
......@@ -414,7 +390,7 @@ export class FileService extends Disposable implements IFileService {
private resolveFileData(resource: uri, options: IResolveContentOptions, token: CancellationToken): TPromise<IContentData> {
const chunkBuffer = BufferPool._64K.acquire();
const chunkBuffer = Buffer.allocUnsafe(64 * 1024);
const result: IContentData = {
encoding: void 0,
......@@ -462,9 +438,6 @@ export class FileService extends Disposable implements IFileService {
decoder.end();
}
// return the shared buffer
BufferPool._64K.release(chunkBuffer);
if (fd) {
fs.close(fd, err => {
if (err) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册