From 2f964f80f463f686fff6f2bba11807a4f6ea325d Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Sat, 5 Feb 2011 07:16:33 -0500 Subject: [PATCH] Speedups --- terminalframebuffer.cpp | 62 +---------------------------------------- terminalframebuffer.hpp | 35 +++++++++++++++++++---- terminalfunctions.cpp | 8 +++++- 3 files changed, 38 insertions(+), 67 deletions(-) diff --git a/terminalframebuffer.cpp b/terminalframebuffer.cpp index 41d3042..d8ce303 100644 --- a/terminalframebuffer.cpp +++ b/terminalframebuffer.cpp @@ -4,18 +4,6 @@ using namespace Terminal; -Cell::Cell() - : contents(), - fallback( false ), - width( 1 ), - renditions(), - need_back_color_erase( true ) -{} - -Row::Row( size_t s_width ) - : cells( s_width ) -{} - void Cell::reset( void ) { contents.clear(); @@ -25,17 +13,6 @@ void Cell::reset( void ) need_back_color_erase = true; } -bool Cell::operator==( const Cell &x ) -{ - assert( !need_back_color_erase ); - assert( !x.need_back_color_erase ); - - return ( (contents == x.contents) - && (fallback == x.fallback) - && (width == x.width) - && (renditions == x.renditions) ); -} - DrawState::DrawState( int s_width, int s_height ) : width( s_width ), height( s_height ), cursor_col( 0 ), cursor_row( 0 ), @@ -144,43 +121,6 @@ void Framebuffer::move_rows_autoscroll( int rows ) ds.move_row( rows, true ); } -Cell *Framebuffer::get_cell( void ) -{ - assert( ds.get_width() ); - assert( ds.get_height() ); - - assert( ds.get_cursor_row() < ds.get_height() ); - assert( ds.get_cursor_col() < ds.get_width() ); - - assert( ds.get_cursor_row() >= 0 ); - assert( ds.get_cursor_col() >= 0 ); - - assert( rows.size() == (size_t)ds.get_height() ); - assert( rows[ ds.get_cursor_row() ].cells.size() == (size_t)ds.get_width() ); - - return &rows[ ds.get_cursor_row() ].cells[ ds.get_cursor_col() ]; -} - -Cell *Framebuffer::get_cell( int row, int col ) -{ - if ( row == -1 ) row = ds.get_cursor_row(); - if ( col == -1 ) col = ds.get_cursor_col(); - - assert( ds.get_width() ); - assert( ds.get_height() ); - - assert( row < ds.get_height() ); - assert( col < ds.get_width() ); - - assert( row >= 0 ); - assert( col >= 0 ); - - assert( rows.size() == (size_t)ds.get_height() ); - assert( rows[ row ].cells.size() == (size_t)ds.get_width() ); - - return &rows[ row ].cells[ col ]; -} - Cell *Framebuffer::get_combining_cell( void ) { if ( (ds.get_combining_char_col() < 0) @@ -427,7 +367,7 @@ void Framebuffer::back_color_erase( void ) for ( int col = 0; col < ds.get_width(); col++ ) { Cell *cell = get_cell( row, col ); if ( cell->need_back_color_erase ) { - assert( cell->renditions.empty() ); + // assert( cell->renditions.empty() ); if ( bg_color > 0 ) { cell->renditions.push_back( bg_color ); } diff --git a/terminalframebuffer.hpp b/terminalframebuffer.hpp index 4defa5f..6747224 100644 --- a/terminalframebuffer.hpp +++ b/terminalframebuffer.hpp @@ -17,18 +17,32 @@ namespace Terminal { std::list renditions; /* e.g., bold, blinking, etc. */ bool need_back_color_erase; - Cell(); + Cell() + : contents(), + fallback( false ), + width( 1 ), + renditions(), + need_back_color_erase( true ) + {} void reset( void ); - bool operator==( const Cell &x ); + inline bool operator==( const Cell &x ) + { + return ( (contents == x.contents) + && (fallback == x.fallback) + && (width == x.width) + && (renditions == x.renditions) ); + } }; class Row { public: std::vector cells; - Row( size_t s_width ); + Row( size_t s_width ) + : cells( s_width ) + {} void insert_cell( int col ); void delete_cell( int col ); @@ -127,8 +141,19 @@ namespace Terminal { void move_rows_autoscroll( int rows ); - Cell *get_cell( void ); - Cell *get_cell( int row, int col ); + inline Cell *get_cell( void ) + { + return &rows[ ds.get_cursor_row() ].cells[ ds.get_cursor_col() ]; + } + + inline Cell *get_cell( int row, int col ) + { + if ( row == -1 ) row = ds.get_cursor_row(); + if ( col == -1 ) col = ds.get_cursor_col(); + + return &rows[ row ].cells[ col ]; + } + Cell *get_combining_cell( void ); void apply_renditions_to_current_cell( void ); diff --git a/terminalfunctions.cpp b/terminalfunctions.cpp index ab144a4..5d1e5ee 100644 --- a/terminalfunctions.cpp +++ b/terminalfunctions.cpp @@ -312,10 +312,16 @@ static Function func_Ctrl_BEL( CONTROL, "\x07", Ctrl_BEL ); /* select graphics rendition -- e.g., bold, blinking, etc. */ void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch ) { - fb->back_color_erase(); + bool bce = false; for ( int i = 0; i < dispatch->param_count(); i++ ) { int rendition = dispatch->getparam( i, 0 ); + if ( (40 <= rendition) && (rendition <= 49) && (!bce) ) { + /* we're changing the background color */ + fb->back_color_erase(); + bce = true; + } + if ( rendition == 0 ) { fb->ds.clear_renditions(); } else {