Skip to content

Commit

Permalink
remove pushRecycling, test case for trimAndRecycle, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jerch committed Oct 26, 2018
1 parent 9820068 commit 93d7a30
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
17 changes: 7 additions & 10 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { IInputHandlingTerminal, IViewport, ICompositionHelper, ITerminalOptions
import { IMouseZoneManager } from './ui/Types';
import { IRenderer } from './renderer/Types';
import { BufferSet } from './BufferSet';
import { Buffer, MAX_BUFFER_SIZE, DEFAULT_ATTR, NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR } from './Buffer';
import { Buffer, MAX_BUFFER_SIZE, DEFAULT_ATTR, NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR, CHAR_DATA_ATTR_INDEX } from './Buffer';
import { CompositionHelper } from './CompositionHelper';
import { EventEmitter } from './common/EventEmitter';
import { Viewport } from './Viewport';
Expand Down Expand Up @@ -1179,23 +1179,19 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
* @param isWrapped Whether the new line is wrapped from the previous line.
*/
public scroll(isWrapped?: boolean): void {
<<<<<<< HEAD
let newLine: IBufferLine;
const useRecycling = this.options.experimentalPushRecycling;
if (useRecycling) {
newLine = this._blankLine;
if (!newLine || newLine.length !== this.cols) {
newLine = this.buffer.getBlankLine(DEFAULT_ATTR, isWrapped);
if (!newLine || newLine.length !== this.cols || newLine.get(0)[CHAR_DATA_ATTR_INDEX] !== this.eraseAttr()) {
newLine = this.buffer.getBlankLine(this.eraseAttr(), isWrapped);
this._blankLine = newLine;
}
newLine.isWrapped = !!(isWrapped);
} else {
newLine = this.buffer.getBlankLine(DEFAULT_ATTR, isWrapped);
newLine = this.buffer.getBlankLine(this.eraseAttr(), isWrapped);
}

=======
const newLine = this.buffer.getBlankLine(this.eraseAttr(), isWrapped);
>>>>>>> master
const topRow = this.buffer.ybase + this.buffer.scrollTop;
const bottomRow = this.buffer.ybase + this.buffer.scrollBottom;

Expand All @@ -1206,9 +1202,10 @@ export class Terminal extends EventEmitter implements ITerminal, IDisposable, II
// Insert the line using the fastest method
if (bottomRow === this.buffer.lines.length - 1) {
if (useRecycling) {
// this.buffer.lines.pushRecycling((item) => (item) ? item.copyFrom(newLine) : newLine.clone());
if (willBufferBeTrimmed) {
(this.buffer.lines as any).trimAndRecycle().copyFrom(newLine);
// Warning: Never call .trimAndRecycle() without the
// willBufferBeTrimmed guard!
this.buffer.lines.trimAndRecycle().copyFrom(newLine);
} else {
this.buffer.lines.push(newLine.clone());
}
Expand Down
16 changes: 16 additions & 0 deletions src/common/CircularList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,20 @@ describe('CircularList', () => {
assert.equal(list.get(3), 4);
});
});
describe('trimAndRecycle', function(): void {
it('should return correct element', function(): void {
const list = new CircularList<number[]>(5);
list.push([0]);
list.push([1]);
list.push([2]);
list.push([3]);
list.push([4]);
assert.equal(list.trimAndRecycle()[0], 0);
assert.equal(list.trimAndRecycle()[0], 1);
assert.equal(list.trimAndRecycle()[0], 2);
assert.equal(list.trimAndRecycle()[0], 3);
assert.equal(list.trimAndRecycle()[0], 4);
assert.equal(list.trimAndRecycle()[0], 0);
});
});
});
23 changes: 7 additions & 16 deletions src/common/CircularList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,14 @@ export class CircularList<T> extends EventEmitter implements ICircularList<T> {
}

/**
* Recycling push variant with a callback.
* The callback gets the value at the current position to be overwritten.
* Return the new value from the callback.
* Recycling trim.
* This is used to recycle buffer lines in Terminal.scroll when
* the list is at maxLength as a push replacement.
* Returns the old line as new one to be recycled.
* Note: There are no bound checks for performance reasons,
* the method is a special optimization for Terminal.scroll,
* do not use it anywhere else.
*/
public pushRecycling(callback: (item: T | undefined) => T): void {
this._array[this._getCyclicIndex(this._length)] = callback(this._array[this._getCyclicIndex(this._length)]);
if (this._length === this._maxLength) {
this._startIndex++;
if (this._startIndex === this._maxLength) {
this._startIndex = 0;
}
this.emit('trim', 1);
} else {
this._length++;
}
}

public trimAndRecycle(): T | undefined {
this._startIndex = ++this._startIndex % this._maxLength;
this.emit('trim', 1);
Expand Down
2 changes: 1 addition & 1 deletion src/common/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface ICircularList<T> extends IEventEmitter {
get(index: number): T | undefined;
set(index: number, value: T): void;
push(value: T): void;
pushRecycling(callback: (item: T | undefined) => T): void;
trimAndRecycle(): T | undefined;
pop(): T | undefined;
splice(start: number, deleteCount: number, ...items: T[]): void;
trimStart(count: number): void;
Expand Down

0 comments on commit 93d7a30

Please sign in to comment.