Cache work cell in hot loops
This commit is contained in:
@@ -9,6 +9,8 @@ import { CellData } from 'common/buffer/CellData';
|
|||||||
import { IBufferService, IOptionsService, IOscLinkService } from 'common/services/Services';
|
import { IBufferService, IOptionsService, IOscLinkService } from 'common/services/Services';
|
||||||
|
|
||||||
export class OscLinkProvider implements ILinkProvider {
|
export class OscLinkProvider implements ILinkProvider {
|
||||||
|
private readonly _workCell = new CellData();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@IBufferService private readonly _bufferService: IBufferService,
|
@IBufferService private readonly _bufferService: IBufferService,
|
||||||
@IOptionsService private readonly _optionsService: IOptionsService,
|
@IOptionsService private readonly _optionsService: IOptionsService,
|
||||||
@@ -25,7 +27,7 @@ export class OscLinkProvider implements ILinkProvider {
|
|||||||
|
|
||||||
const result: ILink[] = [];
|
const result: ILink[] = [];
|
||||||
const linkHandler = this._optionsService.rawOptions.linkHandler;
|
const linkHandler = this._optionsService.rawOptions.linkHandler;
|
||||||
const cell = new CellData();
|
const cell = this._workCell;
|
||||||
const lineLength = line.getTrimmedLength();
|
const lineLength = line.getTrimmedLength();
|
||||||
let currentLinkId = -1;
|
let currentLinkId = -1;
|
||||||
let currentStart = -1;
|
let currentStart = -1;
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export const DEFAULT_ATTR_DATA = Object.freeze(new AttributeData());
|
|||||||
|
|
||||||
// Work variables to avoid garbage collection
|
// Work variables to avoid garbage collection
|
||||||
let $startIndex = 0;
|
let $startIndex = 0;
|
||||||
|
const $workCell = new CellData();
|
||||||
|
|
||||||
/** Factor when to cleanup underlying array buffer after shrinking. */
|
/** Factor when to cleanup underlying array buffer after shrinking. */
|
||||||
const CLEANUP_THRESHOLD = 2;
|
const CLEANUP_THRESHOLD = 2;
|
||||||
@@ -262,9 +263,8 @@ export class BufferLine implements IBufferLine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (n < this.length - pos) {
|
if (n < this.length - pos) {
|
||||||
const cell = new CellData();
|
|
||||||
for (let i = this.length - pos - n - 1; i >= 0; --i) {
|
for (let i = this.length - pos - n - 1; i >= 0; --i) {
|
||||||
this.setCell(pos + n + i, this.loadCell(pos + i, cell));
|
this.setCell(pos + n + i, this.loadCell(pos + i, $workCell));
|
||||||
}
|
}
|
||||||
for (let i = 0; i < n; ++i) {
|
for (let i = 0; i < n; ++i) {
|
||||||
this.setCell(pos + i, fillCellData);
|
this.setCell(pos + i, fillCellData);
|
||||||
@@ -284,9 +284,8 @@ export class BufferLine implements IBufferLine {
|
|||||||
public deleteCells(pos: number, n: number, fillCellData: ICellData): void {
|
public deleteCells(pos: number, n: number, fillCellData: ICellData): void {
|
||||||
pos %= this.length;
|
pos %= this.length;
|
||||||
if (n < this.length - pos) {
|
if (n < this.length - pos) {
|
||||||
const cell = new CellData();
|
|
||||||
for (let i = 0; i < this.length - pos - n; ++i) {
|
for (let i = 0; i < this.length - pos - n; ++i) {
|
||||||
this.setCell(pos + i, this.loadCell(pos + n + i, cell));
|
this.setCell(pos + i, this.loadCell(pos + n + i, $workCell));
|
||||||
}
|
}
|
||||||
for (let i = this.length - n; i < this.length; ++i) {
|
for (let i = this.length - n; i < this.length; ++i) {
|
||||||
this.setCell(i, fillCellData);
|
this.setCell(i, fillCellData);
|
||||||
|
|||||||
Reference in New Issue
Block a user