@@ -55,10 +55,13 @@ export class Buffer implements IBuffer {
5555 }
5656
5757 public setBufferLineFactory ( type : string ) : void {
58+ this . lines . recycling = false ;
59+ this . lines . recycleHeap = [ ] ;
5860 if ( type === 'TypedArray' ) {
5961 if ( this . _bufferLineConstructor !== BufferLineTypedArray ) {
6062 this . _bufferLineConstructor = BufferLineTypedArray ;
6163 this . _recreateLines ( ) ;
64+ this . lines . recycling = true ;
6265 }
6366 } else {
6467 if ( this . _bufferLineConstructor !== BufferLine ) {
@@ -81,8 +84,26 @@ export class Buffer implements IBuffer {
8184 }
8285
8386 public getBlankLine ( attr : number , isWrapped ?: boolean ) : IBufferLine {
84- const fillCharData : CharData = [ attr , NULL_CELL_CHAR , NULL_CELL_WIDTH , NULL_CELL_CODE ] ;
85- return new this . _bufferLineConstructor ( this . _terminal . cols , fillCharData , isWrapped ) ;
87+ // JS array without recycling
88+ if ( this . _bufferLineConstructor === BufferLine ) {
89+ const fillCharData : CharData = [ attr , NULL_CELL_CHAR , NULL_CELL_WIDTH , NULL_CELL_CODE ] ;
90+ return new this . _bufferLineConstructor ( this . _terminal . cols , fillCharData , isWrapped ) ;
91+ }
92+
93+ // typed array with recycling
94+ let blank : IBufferLine = ( this as any ) . _blank ;
95+ if ( ! blank || blank . length !== this . _terminal . cols ) {
96+ const fillCharData : CharData = [ attr , NULL_CELL_CHAR , NULL_CELL_WIDTH , NULL_CELL_CODE ] ;
97+ blank = new this . _bufferLineConstructor ( this . _terminal . cols , fillCharData , isWrapped ) ;
98+ ( this as any ) . _blank = blank ;
99+ }
100+ blank . isWrapped = ! ! ( isWrapped ) ;
101+ const recycled = this . lines . recycleHeap . pop ( ) ;
102+ if ( recycled ) {
103+ recycled . copyFrom ( blank ) ;
104+ return recycled ;
105+ }
106+ return blank . clone ( ) ;
86107 }
87108
88109 public get hasScrollback ( ) : boolean {
@@ -126,7 +147,7 @@ export class Buffer implements IBuffer {
126147 * Clears the buffer to it's initial state, discarding all previous data.
127148 */
128149 public clear ( ) : void {
129- this . setBufferLineFactory ( this . _terminal . options . experimentalBufferLineImpl ) ;
150+ // this.setBufferLineFactory(this._terminal.options.experimentalBufferLineImpl);
130151 this . ydisp = 0 ;
131152 this . ybase = 0 ;
132153 this . y = 0 ;
@@ -135,6 +156,7 @@ export class Buffer implements IBuffer {
135156 this . scrollTop = 0 ;
136157 this . scrollBottom = this . _terminal . rows - 1 ;
137158 this . setupTabStops ( ) ;
159+ this . setBufferLineFactory ( this . _terminal . options . experimentalBufferLineImpl ) ;
138160 }
139161
140162 /**
0 commit comments