Skip to content

Commit b5f1c33

Browse files
authored
Merge pull request #1812 from jerch/default_buffer_to_typedarray
Deprecate JS array based terminal buffer
2 parents 6e45d02 + 6f4a6ef commit b5f1c33

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

src/Buffer.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { CircularList } from './common/CircularList';
77
import { CharData, ITerminal, IBuffer, IBufferLine, BufferIndex, IBufferStringIterator, IBufferStringIteratorResult, IBufferLineConstructor } from './Types';
88
import { EventEmitter } from './common/EventEmitter';
99
import { IMarker } from 'xterm';
10-
import { BufferLine, BufferLineTypedArray } from './BufferLine';
10+
import { BufferLine, BufferLineJSArray } from './BufferLine';
1111
import { DEFAULT_COLOR } from './renderer/atlas/Types';
1212

1313
export const DEFAULT_ATTR = (0 << 18) | (DEFAULT_COLOR << 9) | (256 << 0);
@@ -57,9 +57,9 @@ export class Buffer implements IBuffer {
5757
}
5858

5959
public setBufferLineFactory(type: string): void {
60-
if (type === 'TypedArray') {
61-
if (this._bufferLineConstructor !== BufferLineTypedArray) {
62-
this._bufferLineConstructor = BufferLineTypedArray;
60+
if (type === 'JsArray') {
61+
if (this._bufferLineConstructor !== BufferLineJSArray) {
62+
this._bufferLineConstructor = BufferLineJSArray;
6363
this._recreateLines();
6464
}
6565
} else {

src/BufferLine.ts

+8-15
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer';
77

88
/**
99
* Class representing a terminal line.
10+
*
11+
* @deprecated to be removed with one of the next releases
1012
*/
11-
export class BufferLine implements IBufferLine {
13+
export class BufferLineJSArray implements IBufferLine {
1214
protected _data: CharData[];
1315
public isWrapped = false;
1416
public length: number;
@@ -94,14 +96,14 @@ export class BufferLine implements IBufferLine {
9496
}
9597
}
9698

97-
public copyFrom(line: BufferLine): void {
99+
public copyFrom(line: BufferLineJSArray): void {
98100
this._data = line._data.slice(0);
99101
this.length = line.length;
100102
this.isWrapped = line.isWrapped;
101103
}
102104

103105
public clone(): IBufferLine {
104-
const newLine = new BufferLine(0);
106+
const newLine = new BufferLineJSArray(0);
105107
newLine.copyFrom(this);
106108
return newLine;
107109
}
@@ -119,17 +121,8 @@ const enum Cell {
119121

120122
/**
121123
* Typed array based bufferline implementation.
122-
* Note: Unlike the JS variant the access to the data
123-
* via set/get is always a copy action.
124-
* Sloppy ref style coding will not work anymore:
125-
* line = new BufferLine(10);
126-
* char = line.get(0); // char is a copy
127-
* char[some_index] = 123; // will not update the line
128-
* line.set(0, ch); // do this to update line data
129-
* TODO:
130-
* - provide getData/setData to directly access the data
131124
*/
132-
export class BufferLineTypedArray implements IBufferLine {
125+
export class BufferLine implements IBufferLine {
133126
protected _data: Uint32Array | null = null;
134127
protected _combined: {[index: number]: string} = {};
135128
public length: number;
@@ -248,7 +241,7 @@ export class BufferLineTypedArray implements IBufferLine {
248241
}
249242

250243
/** alter to a full copy of line */
251-
public copyFrom(line: BufferLineTypedArray): void {
244+
public copyFrom(line: BufferLine): void {
252245
if (this.length !== line.length) {
253246
this._data = new Uint32Array(line._data);
254247
} else {
@@ -265,7 +258,7 @@ export class BufferLineTypedArray implements IBufferLine {
265258

266259
/** create a new clone */
267260
public clone(): IBufferLine {
268-
const newLine = new BufferLineTypedArray(0);
261+
const newLine = new BufferLine(0);
269262
// creation of new typed array from another is actually pretty slow :(
270263
// still faster than copying values one by one
271264
newLine._data = new Uint32Array(this._data);

src/Terminal.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ const DEFAULT_OPTIONS: ITerminalOptions = {
106106
theme: null,
107107
rightClickSelectsWord: Browser.isMac,
108108
rendererType: 'canvas',
109-
experimentalBufferLineImpl: 'JsArray'
109+
experimentalBufferLineImpl: 'TypedArray'
110110
};
111111

112112
export class Terminal extends EventEmitter implements ITerminal, IDisposable, IInputHandlingTerminal {
@@ -1179,7 +1179,7 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
11791179
*/
11801180
public scroll(isWrapped: boolean = false): void {
11811181
let newLine: IBufferLine;
1182-
const useRecycling = this.options.experimentalBufferLineImpl === 'TypedArray';
1182+
const useRecycling = this.options.experimentalBufferLineImpl !== 'JsArray';
11831183
if (useRecycling) {
11841184
newLine = this._blankLine;
11851185
if (!newLine || newLine.length !== this.cols || newLine.get(0)[CHAR_DATA_ATTR_INDEX] !== this.eraseAttr()) {

typings/xterm.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ declare module 'xterm' {
108108
* - 'TypedArray': The new experimental implementation based on TypedArrays that is expected to
109109
* significantly boost performance and memory consumption. Use at your own risk.
110110
*
111-
* This option will be removed in the future.
111+
* @deprecated This option will be removed in the future.
112112
*/
113113
experimentalBufferLineImpl?: 'JsArray' | 'TypedArray';
114114

0 commit comments

Comments
 (0)