fix resize edge cases: always report cleanup state
This commit is contained in:
Vendored
+1
-1
@@ -205,7 +205,7 @@ export interface IBufferLine {
|
|||||||
insertCells(pos: number, n: number, ch: ICellData, eraseAttr?: IAttributeData): void;
|
insertCells(pos: number, n: number, ch: ICellData, eraseAttr?: IAttributeData): void;
|
||||||
deleteCells(pos: number, n: number, fill: ICellData, eraseAttr?: IAttributeData): void;
|
deleteCells(pos: number, n: number, fill: ICellData, eraseAttr?: IAttributeData): void;
|
||||||
replaceCells(start: number, end: number, fill: ICellData, eraseAttr?: IAttributeData, respectProtect?: boolean): void;
|
replaceCells(start: number, end: number, fill: ICellData, eraseAttr?: IAttributeData, respectProtect?: boolean): void;
|
||||||
resize(cols: number, fill: ICellData): void;
|
resize(cols: number, fill: ICellData): boolean;
|
||||||
fill(fillCellData: ICellData, respectProtect?: boolean): void;
|
fill(fillCellData: ICellData, respectProtect?: boolean): void;
|
||||||
copyFrom(line: IBufferLine): void;
|
copyFrom(line: IBufferLine): void;
|
||||||
clone(): IBufferLine;
|
clone(): IBufferLine;
|
||||||
|
|||||||
@@ -338,10 +338,16 @@ export class BufferLine implements IBufferLine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resize BufferLine to `cols` filling excess cells with `fillCellData`.
|
||||||
|
* The underlying array buffer will not change if there is still enough space
|
||||||
|
* to hold the new buffer line data.
|
||||||
|
* Returns a boolean indicating, whether a `cleanBuffer` call would free
|
||||||
|
* excess memory (after shrinking > CLEANUP_THRESHOLD).
|
||||||
|
*/
|
||||||
public resize(cols: number, fillCellData: ICellData): boolean {
|
public resize(cols: number, fillCellData: ICellData): boolean {
|
||||||
let needsCleanup = false;
|
|
||||||
if (cols === this.length) {
|
if (cols === this.length) {
|
||||||
return needsCleanup;
|
return this._data.length * 4 < this._data.buffer.byteLength * CLEANUP_THRESHOLD;
|
||||||
}
|
}
|
||||||
const fourByteCells = cols * CELL_SIZE;
|
const fourByteCells = cols * CELL_SIZE;
|
||||||
if (cols > this.length) {
|
if (cols > this.length) {
|
||||||
@@ -362,7 +368,6 @@ export class BufferLine implements IBufferLine {
|
|||||||
} else {
|
} else {
|
||||||
// optimization: just shrink the view on existing buffer
|
// optimization: just shrink the view on existing buffer
|
||||||
this._data = this._data.subarray(0, fourByteCells);
|
this._data = this._data.subarray(0, fourByteCells);
|
||||||
needsCleanup = fourByteCells * 4 < this._data.buffer.byteLength * CLEANUP_THRESHOLD;
|
|
||||||
// Remove any cut off combined data
|
// Remove any cut off combined data
|
||||||
const keys = Object.keys(this._combined);
|
const keys = Object.keys(this._combined);
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
@@ -381,7 +386,7 @@ export class BufferLine implements IBufferLine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.length = cols;
|
this.length = cols;
|
||||||
return needsCleanup;
|
return fourByteCells * 4 < this._data.buffer.byteLength * CLEANUP_THRESHOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user