lazy cleanup on buffer

This commit is contained in:
Jörg Breitbart
2022-09-28 15:57:58 +02:00
parent e58f73dc82
commit 785b932d75
3 changed files with 32 additions and 6 deletions
+4 -4
View File
@@ -347,7 +347,7 @@ export class BufferLine implements IBufferLine {
*/
public resize(cols: number, fillCellData: ICellData): boolean {
if (cols === this.length) {
return this._data.length * 4 < this._data.buffer.byteLength * CLEANUP_THRESHOLD;
return this._data.length * 4 * CLEANUP_THRESHOLD < this._data.buffer.byteLength;
}
const uint32Cells = cols * CELL_SIZE;
if (cols > this.length) {
@@ -384,7 +384,7 @@ export class BufferLine implements IBufferLine {
}
}
this.length = cols;
return uint32Cells * 4 < this._data.buffer.byteLength * CLEANUP_THRESHOLD;
return uint32Cells * 4 * CLEANUP_THRESHOLD < this._data.buffer.byteLength;
}
/**
@@ -393,8 +393,8 @@ export class BufferLine implements IBufferLine {
* memory by a factor of CLEANUP_THRESHOLD.
* Returns 0 or 1 indicating whether a cleanup happened.
*/
public cleanupBuffer(): number {
if (this._data.length * 4 < this._data.buffer.byteLength * CLEANUP_THRESHOLD) {
public cleanupMemory(): number {
if (this._data.length * 4 * CLEANUP_THRESHOLD < this._data.buffer.byteLength) {
const data = new Uint32Array(this._data.length);
data.set(this._data);
this._data = data;