Prefer early exit/break to large conditional blocks.
Some of these are large and contain smaller unrelated refactors.
This commit is contained in:
@@ -314,7 +314,9 @@ bool STMClient::process_user_input( int fd )
|
|||||||
|
|
||||||
NetworkType &net = *network;
|
NetworkType &net = *network;
|
||||||
|
|
||||||
if ( !net.shutdown_in_progress() ) {
|
if ( net.shutdown_in_progress() ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
overlays.get_prediction_engine().set_local_frame_sent( net.get_sent_state_last() );
|
overlays.get_prediction_engine().set_local_frame_sent( net.get_sent_state_last() );
|
||||||
|
|
||||||
/* Don't predict for bulk data. */
|
/* Don't predict for bulk data. */
|
||||||
@@ -336,9 +338,8 @@ bool STMClient::process_user_input( int fd )
|
|||||||
overlays.get_notification_engine().set_notification_string( wstring( L"Exiting on user request..." ), true );
|
overlays.get_notification_engine().set_notification_string( wstring( L"Exiting on user request..." ), true );
|
||||||
net.start_shutdown();
|
net.start_shutdown();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
} else if ( the_byte == 0x1a ) { /* Suspend sequence is escape_key Ctrl-Z */
|
} else if ( the_byte == 0x1a ) { /* Suspend sequence is escape_key Ctrl-Z */
|
||||||
/* Restore terminal and terminal-driver state */
|
/* Restore terminal and terminal-driver state */
|
||||||
swrite( STDOUT_FILENO, display.close().c_str() );
|
swrite( STDOUT_FILENO, display.close().c_str() );
|
||||||
@@ -390,7 +391,6 @@ bool STMClient::process_user_input( int fd )
|
|||||||
|
|
||||||
net.get_current_state().push_back( Parser::UserByte( the_byte ) );
|
net.get_current_state().push_back( Parser::UserByte( the_byte ) );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,10 @@ Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb, int row,
|
|||||||
const Cell ¤t = *( fb.get_cell( row, col ) );
|
const Cell ¤t = *( fb.get_cell( row, col ) );
|
||||||
|
|
||||||
/* see if it hasn't been updated yet */
|
/* see if it hasn't been updated yet */
|
||||||
if ( late_ack >= expiration_frame ) {
|
if ( late_ack < expiration_frame ) {
|
||||||
|
return Pending;
|
||||||
|
}
|
||||||
|
|
||||||
if ( unknown ) {
|
if ( unknown ) {
|
||||||
return CorrectNoCredit;
|
return CorrectNoCredit;
|
||||||
}
|
}
|
||||||
@@ -107,15 +110,10 @@ Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb, int row,
|
|||||||
}
|
}
|
||||||
if ( it == original_contents.end() ) {
|
if ( it == original_contents.end() ) {
|
||||||
return Correct;
|
return Correct;
|
||||||
} else {
|
}
|
||||||
return CorrectNoCredit;
|
return CorrectNoCredit;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return IncorrectOrExpired;
|
return IncorrectOrExpired;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Pending;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Validity ConditionalCursorMove::get_validity( const Framebuffer &fb,
|
Validity ConditionalCursorMove::get_validity( const Framebuffer &fb,
|
||||||
|
|||||||
@@ -523,7 +523,9 @@ string Connection::recv_one( int sock_to_recv, bool nonblocking )
|
|||||||
|
|
||||||
dos_assert( p.direction == (server ? TO_SERVER : TO_CLIENT) ); /* prevent malicious playback to sender */
|
dos_assert( p.direction == (server ? TO_SERVER : TO_CLIENT) ); /* prevent malicious playback to sender */
|
||||||
|
|
||||||
if ( p.seq >= expected_receiver_seq ) { /* don't use out-of-order packets for timestamp or targeting */
|
if ( p.seq < expected_receiver_seq ) { /* don't use (but do return) out-of-order packets for timestamp or targeting */
|
||||||
|
return p.payload;
|
||||||
|
}
|
||||||
expected_receiver_seq = p.seq + 1; /* this is security-sensitive because a replay attack could otherwise
|
expected_receiver_seq = p.seq + 1; /* this is security-sensitive because a replay attack could otherwise
|
||||||
screw up the timestamp and targeting */
|
screw up the timestamp and targeting */
|
||||||
|
|
||||||
@@ -564,9 +566,9 @@ string Connection::recv_one( int sock_to_recv, bool nonblocking )
|
|||||||
has_remote_addr = true;
|
has_remote_addr = true;
|
||||||
last_heard = timestamp();
|
last_heard = timestamp();
|
||||||
|
|
||||||
if ( server ) { /* only client can roam */
|
if ( server && /* only client can roam */
|
||||||
if ( remote_addr_len != header.msg_namelen ||
|
( remote_addr_len != header.msg_namelen ||
|
||||||
memcmp( &remote_addr, &packet_remote_addr, remote_addr_len ) != 0 ) {
|
memcmp( &remote_addr, &packet_remote_addr, remote_addr_len ) != 0 ) ) {
|
||||||
remote_addr = packet_remote_addr;
|
remote_addr = packet_remote_addr;
|
||||||
remote_addr_len = header.msg_namelen;
|
remote_addr_len = header.msg_namelen;
|
||||||
char host[ NI_MAXHOST ], serv[ NI_MAXSERV ];
|
char host[ NI_MAXHOST ], serv[ NI_MAXSERV ];
|
||||||
@@ -579,10 +581,7 @@ string Connection::recv_one( int sock_to_recv, bool nonblocking )
|
|||||||
fprintf( stderr, "Server now attached to client at %s:%s\n",
|
fprintf( stderr, "Server now attached to client at %s:%s\n",
|
||||||
host, serv );
|
host, serv );
|
||||||
}
|
}
|
||||||
}
|
return p.payload;
|
||||||
}
|
|
||||||
|
|
||||||
return p.payload; /* we do return out-of-order or duplicated packets to caller */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Connection::port( void ) const
|
std::string Connection::port( void ) const
|
||||||
|
|||||||
@@ -181,7 +181,9 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const
|
|||||||
for ( int row = 0; row < f.ds.get_height(); row++ ) {
|
for ( int row = 0; row < f.ds.get_height(); row++ ) {
|
||||||
const Row *new_row = f.get_row( 0 );
|
const Row *new_row = f.get_row( 0 );
|
||||||
const Row *old_row = &*rows.at( row );
|
const Row *old_row = &*rows.at( row );
|
||||||
if ( new_row == old_row || *new_row == *old_row ) {
|
if ( ! ( new_row == old_row || *new_row == *old_row ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
/* if row 0, we're looking at ourselves and probably didn't scroll */
|
/* if row 0, we're looking at ourselves and probably didn't scroll */
|
||||||
if ( row == 0 ) {
|
if ( row == 0 ) {
|
||||||
break;
|
break;
|
||||||
@@ -204,7 +206,6 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( scroll_height ) {
|
if ( scroll_height ) {
|
||||||
frame_y = scroll_height;
|
frame_y = scroll_height;
|
||||||
@@ -458,8 +459,10 @@ bool Display::put_row( bool initialized, FrameState &frame, const Framebuffer &f
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( wrote_last_cell
|
if ( ! ( wrote_last_cell
|
||||||
&& (frame_y < f.ds.get_height() - 1) ) {
|
&& (frame_y < f.ds.get_height() - 1) ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
/* To hint that a word-select should group the end of one line
|
/* To hint that a word-select should group the end of one line
|
||||||
with the beginning of the next, we let the real cursor
|
with the beginning of the next, we let the real cursor
|
||||||
actually wrap around in cases where it wrapped around for us. */
|
actually wrap around in cases where it wrapped around for us. */
|
||||||
@@ -468,13 +471,11 @@ bool Display::put_row( bool initialized, FrameState &frame, const Framebuffer &f
|
|||||||
frame.cursor_x = 0;
|
frame.cursor_x = 0;
|
||||||
frame.cursor_y++;
|
frame.cursor_y++;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
/* Resort to CR/LF and update our cursor. */
|
/* Resort to CR/LF and update our cursor. */
|
||||||
frame.append( "\r\n" );
|
frame.append( "\r\n" );
|
||||||
frame.cursor_x = 0;
|
frame.cursor_x = 0;
|
||||||
frame.cursor_y++;
|
frame.cursor_y++;
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user