Reduce use of malloc()

This commit is contained in:
Keith Winstein
2011-10-13 15:25:48 -04:00
parent 5fc16a4a89
commit aab2ac65be
3 changed files with 15 additions and 7 deletions
+3 -3
View File
@@ -128,9 +128,9 @@ void STMClient::output_new_frame( void )
overlays.apply( new_state );
/* calculate minimal difference from where we are */
string diff = Terminal::Display::new_frame( !repaint_requested,
*local_framebuffer,
new_state );
const string diff( Terminal::Display::new_frame( !repaint_requested,
*local_framebuffer,
new_state ) );
swrite( STDOUT_FILENO, diff.data(), diff.size() );
*local_framebuffer = new_state;
+2 -2
View File
@@ -170,7 +170,7 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const
/* have renditions changed? */
if ( (!initialized)
|| (f.ds.get_renditions().sgr() != frame.current_rendition_string) ) {
frame.append( f.ds.get_renditions().sgr() );
frame.appendstring( f.ds.get_renditions().sgr() );
frame.current_rendition_string = f.ds.get_renditions().sgr();
}
@@ -197,7 +197,7 @@ void Display::put_cell( bool initialized, FrameState &frame, const Framebuffer &
if ( frame.current_rendition_string != rendition_str ) {
/* print renditions */
frame.append( rendition_str );
frame.appendstring( rendition_str );
frame.current_rendition_string = rendition_str;
}
+10 -2
View File
@@ -15,8 +15,16 @@ namespace Terminal {
Framebuffer last_frame;
FrameState( const Framebuffer &s_last ) : x(0), y(0), str(), cursor_x(0), cursor_y(0), current_rendition_string(), last_frame( s_last ) {}
void append( std::string s ) { str.append( s ); }
FrameState( const Framebuffer &s_last )
: x(0), y(0),
str(), cursor_x(0), cursor_y(0), current_rendition_string(),
last_frame( s_last )
{
str.reserve( 1024 );
}
void append( const char * s ) { str.append( s ); }
void appendstring( const std::string s ) { str.append( s ); }
void append_silent_move( int y, int x );
};