Reduce character cell lookups in Emulator::print().

This commit is contained in:
John Hood
2014-09-15 03:14:00 -04:00
parent 589d21bbf2
commit f5d814a9c4
3 changed files with 34 additions and 25 deletions
+10 -4
View File
@@ -65,8 +65,6 @@ void Emulator::print( const Parser::Print *act )
Cell *this_cell = fb.get_mutable_cell(); Cell *this_cell = fb.get_mutable_cell();
Cell *combining_cell = fb.get_combining_cell(); /* can be null if we were resized */
switch ( chwidth ) { switch ( chwidth ) {
case 1: /* normal character */ case 1: /* normal character */
case 2: /* wide character */ case 2: /* wide character */
@@ -74,6 +72,7 @@ void Emulator::print( const Parser::Print *act )
fb.get_mutable_row( -1 )->set_wrap( true ); fb.get_mutable_row( -1 )->set_wrap( true );
fb.ds.move_col( 0 ); fb.ds.move_col( 0 );
fb.move_rows_autoscroll( 1 ); fb.move_rows_autoscroll( 1 );
this_cell = NULL;
} else if ( fb.ds.auto_wrap_mode } else if ( fb.ds.auto_wrap_mode
&& (chwidth == 2) && (chwidth == 2)
&& (fb.ds.get_cursor_col() == fb.ds.get_width() - 1) ) { && (fb.ds.get_cursor_col() == fb.ds.get_width() - 1) ) {
@@ -86,20 +85,24 @@ void Emulator::print( const Parser::Print *act )
because a wide char was wrapped to the next line. */ because a wide char was wrapped to the next line. */
fb.ds.move_col( 0 ); fb.ds.move_col( 0 );
fb.move_rows_autoscroll( 1 ); fb.move_rows_autoscroll( 1 );
this_cell = NULL;
} }
if ( fb.ds.insert_mode ) { if ( fb.ds.insert_mode ) {
for ( int i = 0; i < chwidth; i++ ) { for ( int i = 0; i < chwidth; i++ ) {
fb.insert_cell( fb.ds.get_cursor_row(), fb.ds.get_cursor_col() ); fb.insert_cell( fb.ds.get_cursor_row(), fb.ds.get_cursor_col() );
} }
this_cell = NULL;
} }
if (!this_cell) {
this_cell = fb.get_mutable_cell(); this_cell = fb.get_mutable_cell();
}
fb.reset_cell( this_cell ); fb.reset_cell( this_cell );
this_cell->append( act->ch ); this_cell->append( act->ch );
this_cell->width = chwidth; this_cell->width = chwidth;
fb.apply_renditions_to_current_cell(); fb.apply_renditions_to_cell( this_cell );
if ( chwidth == 2 ) { /* erase overlapped cell */ if ( chwidth == 2 ) { /* erase overlapped cell */
if ( fb.ds.get_cursor_col() + 1 < fb.ds.get_width() ) { if ( fb.ds.get_cursor_col() + 1 < fb.ds.get_width() ) {
@@ -112,6 +115,8 @@ void Emulator::print( const Parser::Print *act )
act->handled = true; act->handled = true;
break; break;
case 0: /* combining character */ case 0: /* combining character */
{
Cell *combining_cell = fb.get_combining_cell(); /* can be null if we were resized */
if ( combining_cell == NULL ) { /* character is now offscreen */ if ( combining_cell == NULL ) { /* character is now offscreen */
act->handled = true; act->handled = true;
break; break;
@@ -129,9 +134,10 @@ void Emulator::print( const Parser::Print *act )
} }
if ( combining_cell->contents.size() < 32 ) { if ( combining_cell->contents.size() < 32 ) {
/* seems like a reasonable limit on combining characters */ /* seems like a reasonable limit on combining characters */
combining_cell->contents.push_back( act->ch ); combining_cell->append( act->ch );
} }
act->handled = true; act->handled = true;
}
break; break;
case -1: /* unprintable character */ case -1: /* unprintable character */
break; break;
+5 -2
View File
@@ -256,9 +256,12 @@ int DrawState::limit_bottom( void ) const
return origin_mode ? scrolling_region_bottom_row : height - 1; return origin_mode ? scrolling_region_bottom_row : height - 1;
} }
void Framebuffer::apply_renditions_to_current_cell( void ) void Framebuffer::apply_renditions_to_cell( Cell *cell )
{ {
get_mutable_cell()->renditions = ds.get_renditions(); if (!cell) {
cell = get_mutable_cell();
}
cell->renditions = ds.get_renditions();
} }
SavedCursor::SavedCursor() SavedCursor::SavedCursor()
+1 -1
View File
@@ -370,7 +370,7 @@ namespace Terminal {
Cell *get_combining_cell( void ); Cell *get_combining_cell( void );
void apply_renditions_to_current_cell( void ); void apply_renditions_to_cell( Cell *cell );
void insert_line( int before_row, int count ); void insert_line( int before_row, int count );
void delete_line( int row, int count ); void delete_line( int row, int count );