Skip to content

Commit 7e3c41b

Browse files
authored
Merge pull request #5643 from Tyriar/cacheWorkCell
Cache work cell in hot loops
2 parents 21e4301 + 3ef43ae commit 7e3c41b

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/browser/OscLinkProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { CellData } from 'common/buffer/CellData';
99
import { IBufferService, IOptionsService, IOscLinkService } from 'common/services/Services';
1010

1111
export class OscLinkProvider implements ILinkProvider {
12+
private readonly _workCell = new CellData();
13+
1214
constructor(
1315
@IBufferService private readonly _bufferService: IBufferService,
1416
@IOptionsService private readonly _optionsService: IOptionsService,
@@ -25,7 +27,7 @@ export class OscLinkProvider implements ILinkProvider {
2527

2628
const result: ILink[] = [];
2729
const linkHandler = this._optionsService.rawOptions.linkHandler;
28-
const cell = new CellData();
30+
const cell = this._workCell;
2931
const lineLength = line.getTrimmedLength();
3032
let currentLinkId = -1;
3133
let currentStart = -1;

src/common/buffer/BufferLine.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const DEFAULT_ATTR_DATA = Object.freeze(new AttributeData());
3939

4040
// Work variables to avoid garbage collection
4141
let $startIndex = 0;
42+
const $workCell = new CellData();
4243

4344
/** Factor when to cleanup underlying array buffer after shrinking. */
4445
const CLEANUP_THRESHOLD = 2;
@@ -262,9 +263,8 @@ export class BufferLine implements IBufferLine {
262263
}
263264

264265
if (n < this.length - pos) {
265-
const cell = new CellData();
266266
for (let i = this.length - pos - n - 1; i >= 0; --i) {
267-
this.setCell(pos + n + i, this.loadCell(pos + i, cell));
267+
this.setCell(pos + n + i, this.loadCell(pos + i, $workCell));
268268
}
269269
for (let i = 0; i < n; ++i) {
270270
this.setCell(pos + i, fillCellData);
@@ -284,9 +284,8 @@ export class BufferLine implements IBufferLine {
284284
public deleteCells(pos: number, n: number, fillCellData: ICellData): void {
285285
pos %= this.length;
286286
if (n < this.length - pos) {
287-
const cell = new CellData();
288287
for (let i = 0; i < this.length - pos - n; ++i) {
289-
this.setCell(pos + i, this.loadCell(pos + n + i, cell));
288+
this.setCell(pos + i, this.loadCell(pos + n + i, $workCell));
290289
}
291290
for (let i = this.length - n; i < this.length; ++i) {
292291
this.setCell(i, fillCellData);

0 commit comments

Comments
 (0)