Prefer early exit/break to large conditional blocks.
Some of these are large and contain smaller unrelated refactors.
This commit is contained in:
@@ -181,29 +181,30 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const
|
||||
for ( int row = 0; row < f.ds.get_height(); row++ ) {
|
||||
const Row *new_row = f.get_row( 0 );
|
||||
const Row *old_row = &*rows.at( row );
|
||||
if ( new_row == old_row || *new_row == *old_row ) {
|
||||
/* if row 0, we're looking at ourselves and probably didn't scroll */
|
||||
if ( row == 0 ) {
|
||||
break;
|
||||
}
|
||||
/* found a scroll */
|
||||
lines_scrolled = row;
|
||||
scroll_height = 1;
|
||||
|
||||
/* how big is the region that was scrolled? */
|
||||
for ( int region_height = 1;
|
||||
lines_scrolled + region_height < f.ds.get_height();
|
||||
region_height++ ) {
|
||||
if ( *f.get_row( region_height )
|
||||
== *rows.at( lines_scrolled + region_height ) ) {
|
||||
scroll_height = region_height + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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 ) {
|
||||
break;
|
||||
}
|
||||
/* found a scroll */
|
||||
lines_scrolled = row;
|
||||
scroll_height = 1;
|
||||
|
||||
/* how big is the region that was scrolled? */
|
||||
for ( int region_height = 1;
|
||||
lines_scrolled + region_height < f.ds.get_height();
|
||||
region_height++ ) {
|
||||
if ( *f.get_row( region_height )
|
||||
== *rows.at( lines_scrolled + region_height ) ) {
|
||||
scroll_height = region_height + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ( scroll_height ) {
|
||||
@@ -458,23 +459,23 @@ bool Display::put_row( bool initialized, FrameState &frame, const Framebuffer &f
|
||||
}
|
||||
}
|
||||
|
||||
if ( wrote_last_cell
|
||||
&& (frame_y < f.ds.get_height() - 1) ) {
|
||||
/* To hint that a word-select should group the end of one line
|
||||
with the beginning of the next, we let the real cursor
|
||||
actually wrap around in cases where it wrapped around for us. */
|
||||
if ( wrap_this ) {
|
||||
/* Update our cursor, and ask for wrap on the next row. */
|
||||
frame.cursor_x = 0;
|
||||
frame.cursor_y++;
|
||||
return true;
|
||||
} else {
|
||||
/* Resort to CR/LF and update our cursor. */
|
||||
frame.append( "\r\n" );
|
||||
frame.cursor_x = 0;
|
||||
frame.cursor_y++;
|
||||
}
|
||||
if ( ! ( wrote_last_cell
|
||||
&& (frame_y < f.ds.get_height() - 1) ) ) {
|
||||
return false;
|
||||
}
|
||||
/* To hint that a word-select should group the end of one line
|
||||
with the beginning of the next, we let the real cursor
|
||||
actually wrap around in cases where it wrapped around for us. */
|
||||
if ( wrap_this ) {
|
||||
/* Update our cursor, and ask for wrap on the next row. */
|
||||
frame.cursor_x = 0;
|
||||
frame.cursor_y++;
|
||||
return true;
|
||||
}
|
||||
/* Resort to CR/LF and update our cursor. */
|
||||
frame.append( "\r\n" );
|
||||
frame.cursor_x = 0;
|
||||
frame.cursor_y++;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user