Skip to content

Commit 716a8d5

Browse files
authored
Merge pull request #1403 from jerch/performance_optimizations
performance optimizations
2 parents a3ce881 + 9593cb0 commit 716a8d5

File tree

5 files changed

+135
-97
lines changed

5 files changed

+135
-97
lines changed

src/Buffer.ts

+20-25
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ export const MAX_BUFFER_SIZE = 4294967295; // 2^32 - 1
2222
* - scroll position
2323
*/
2424
export class Buffer implements IBuffer {
25-
private _lines: CircularList<LineData>;
26-
25+
public lines: CircularList<LineData>;
2726
public ydisp: number;
2827
public ybase: number;
2928
public y: number;
@@ -48,10 +47,6 @@ export class Buffer implements IBuffer {
4847
this.clear();
4948
}
5049

51-
public get lines(): CircularList<LineData> {
52-
return this._lines;
53-
}
54-
5550
public get hasScrollback(): boolean {
5651
return this._hasScrollback && this.lines.maxLength > this._terminal.rows;
5752
}
@@ -81,7 +76,7 @@ export class Buffer implements IBuffer {
8176
* Fills the buffer's viewport with blank lines.
8277
*/
8378
public fillViewportRows(): void {
84-
if (this._lines.length === 0) {
79+
if (this.lines.length === 0) {
8580
let i = this._terminal.rows;
8681
while (i--) {
8782
this.lines.push(this._terminal.blankLine());
@@ -97,7 +92,7 @@ export class Buffer implements IBuffer {
9792
this.ybase = 0;
9893
this.y = 0;
9994
this.x = 0;
100-
this._lines = new CircularList<LineData>(this._getCorrectBufferLength(this._terminal.rows));
95+
this.lines = new CircularList<LineData>(this._getCorrectBufferLength(this._terminal.rows));
10196
this.scrollTop = 0;
10297
this.scrollBottom = this._terminal.rows - 1;
10398
this.setupTabStops();
@@ -112,19 +107,19 @@ export class Buffer implements IBuffer {
112107
// Increase max length if needed before adjustments to allow space to fill
113108
// as required.
114109
const newMaxLength = this._getCorrectBufferLength(newRows);
115-
if (newMaxLength > this._lines.maxLength) {
116-
this._lines.maxLength = newMaxLength;
110+
if (newMaxLength > this.lines.maxLength) {
111+
this.lines.maxLength = newMaxLength;
117112
}
118113

119114
// The following adjustments should only happen if the buffer has been
120115
// initialized/filled.
121-
if (this._lines.length > 0) {
116+
if (this.lines.length > 0) {
122117
// Deal with columns increasing (we don't do anything when columns reduce)
123118
if (this._terminal.cols < newCols) {
124119
const ch: CharData = [this._terminal.defAttr, ' ', 1, 32]; // does xterm use the default attr?
125-
for (let i = 0; i < this._lines.length; i++) {
126-
while (this._lines.get(i).length < newCols) {
127-
this._lines.get(i).push(ch);
120+
for (let i = 0; i < this.lines.length; i++) {
121+
while (this.lines.get(i).length < newCols) {
122+
this.lines.get(i).push(ch);
128123
}
129124
}
130125
}
@@ -133,8 +128,8 @@ export class Buffer implements IBuffer {
133128
let addToY = 0;
134129
if (this._terminal.rows < newRows) {
135130
for (let y = this._terminal.rows; y < newRows; y++) {
136-
if (this._lines.length < newRows + this.ybase) {
137-
if (this.ybase > 0 && this._lines.length <= this.ybase + this.y + addToY + 1) {
131+
if (this.lines.length < newRows + this.ybase) {
132+
if (this.ybase > 0 && this.lines.length <= this.ybase + this.y + addToY + 1) {
138133
// There is room above the buffer and there are no empty elements below the line,
139134
// scroll up
140135
this.ybase--;
@@ -146,16 +141,16 @@ export class Buffer implements IBuffer {
146141
} else {
147142
// Add a blank line if there is no buffer left at the top to scroll to, or if there
148143
// are blank lines after the cursor
149-
this._lines.push(this._terminal.blankLine(undefined, undefined, newCols));
144+
this.lines.push(this._terminal.blankLine(undefined, undefined, newCols));
150145
}
151146
}
152147
}
153148
} else { // (this._terminal.rows >= newRows)
154149
for (let y = this._terminal.rows; y > newRows; y--) {
155-
if (this._lines.length > newRows + this.ybase) {
156-
if (this._lines.length > this.ybase + this.y + 1) {
150+
if (this.lines.length > newRows + this.ybase) {
151+
if (this.lines.length > this.ybase + this.y + 1) {
157152
// The line is a blank line below the cursor, remove it
158-
this._lines.pop();
153+
this.lines.pop();
159154
} else {
160155
// The line is the cursor, scroll down
161156
this.ybase++;
@@ -167,15 +162,15 @@ export class Buffer implements IBuffer {
167162

168163
// Reduce max length if needed after adjustments, this is done after as it
169164
// would otherwise cut data from the bottom of the buffer.
170-
if (newMaxLength < this._lines.maxLength) {
165+
if (newMaxLength < this.lines.maxLength) {
171166
// Trim from the top of the buffer and adjust ybase and ydisp.
172-
const amountToTrim = this._lines.length - newMaxLength;
167+
const amountToTrim = this.lines.length - newMaxLength;
173168
if (amountToTrim > 0) {
174-
this._lines.trimStart(amountToTrim);
169+
this.lines.trimStart(amountToTrim);
175170
this.ybase = Math.max(this.ybase - amountToTrim, 0);
176171
this.ydisp = Math.max(this.ydisp - amountToTrim, 0);
177172
}
178-
this._lines.maxLength = newMaxLength;
173+
this.lines.maxLength = newMaxLength;
179174
}
180175

181176
// Make sure that the cursor stays on screen
@@ -310,7 +305,7 @@ export class Buffer implements IBuffer {
310305
public addMarker(y: number): Marker {
311306
const marker = new Marker(y);
312307
this.markers.push(marker);
313-
marker.disposables.push(this._lines.addDisposableListener('trim', amount => {
308+
marker.disposables.push(this.lines.addDisposableListener('trim', amount => {
314309
marker.line -= amount;
315310
// The marker should be disposed when the line is trimmed from the buffer
316311
if (marker.line < 0) {

0 commit comments

Comments
 (0)