From b1a6f7c1448481b616a787bc8ab10b29aca9750f Mon Sep 17 00:00:00 2001 From: John Hood Date: Mon, 7 Nov 2016 00:43:33 -0500 Subject: [PATCH] Eliminate unnecessary, trailing else conditional blocks. --- src/frontend/terminaloverlay.cc | 3 +- src/statesync/completeterminal.cc | 3 +- src/terminal/terminaldispatcher.cc | 9 +++--- src/terminal/terminalframebuffer.cc | 44 ++++++++++++++--------------- src/terminal/terminaluserinput.cc | 20 ++++++------- src/util/locale_utils.cc | 6 ++-- src/util/swrite.cc | 3 +- 7 files changed, 38 insertions(+), 50 deletions(-) diff --git a/src/frontend/terminaloverlay.cc b/src/frontend/terminaloverlay.cc index 43d13d4..f864aeb 100644 --- a/src/frontend/terminaloverlay.cc +++ b/src/frontend/terminaloverlay.cc @@ -137,9 +137,8 @@ Validity ConditionalCursorMove::get_validity( const Framebuffer &fb, if ( (fb.ds.get_cursor_col() == col) && (fb.ds.get_cursor_row() == row) ) { return Correct; - } else { - return IncorrectOrExpired; } + return IncorrectOrExpired; } return Pending; diff --git a/src/statesync/completeterminal.cc b/src/statesync/completeterminal.cc index 2e2ebee..eddfda5 100644 --- a/src/statesync/completeterminal.cc +++ b/src/statesync/completeterminal.cc @@ -173,9 +173,8 @@ int Complete::wait_time( uint64_t now ) const uint64_t next_echo_ack_time = it->second + ECHO_TIMEOUT; if ( next_echo_ack_time <= now ) { return 0; - } else { - return next_echo_ack_time - now; } + return next_echo_ack_time - now; } bool Complete::compare( const Complete &other ) const diff --git a/src/terminal/terminaldispatcher.cc b/src/terminal/terminaldispatcher.cc index 1e31491..13ac829 100644 --- a/src/terminal/terminaldispatcher.cc +++ b/src/terminal/terminaldispatcher.cc @@ -226,12 +226,11 @@ void Dispatcher::dispatch( Function_Type type, const Parser::Action *act, Frameb /* unknown function */ fb->ds.next_print_will_wrap = false; return; - } else { - if ( i->second.clears_wrap_state ) { - fb->ds.next_print_will_wrap = false; - } - return i->second.function( fb, this ); } + if ( i->second.clears_wrap_state ) { + fb->ds.next_print_will_wrap = false; + } + i->second.function( fb, this ); } void Dispatcher::OSC_put( const Parser::OSC_Put *act ) diff --git a/src/terminal/terminalframebuffer.cc b/src/terminal/terminalframebuffer.cc index 316e299..a724afa 100644 --- a/src/terminal/terminalframebuffer.cc +++ b/src/terminal/terminalframebuffer.cc @@ -229,14 +229,13 @@ int DrawState::get_next_tab( int count ) const } } return -1; - } else { - for ( int i = cursor_col - 1; i > 0; i-- ) { - if ( tabs[ i ] && ++count == 0 ) { - return i; - } - } - return 0; } + for ( int i = cursor_col - 1; i > 0; i-- ) { + if ( tabs[ i ] && ++count == 0 ) { + return i; + } + } + return 0; } void DrawState::set_scrolling_region( int top, int bottom ) @@ -597,23 +596,22 @@ std::string Cell::debug_contents( void ) const { if ( contents.empty() ) { return "'_' ()"; - } else { - std::string chars( 1, '\'' ); - print_grapheme( chars ); - chars.append( "' [" ); - const char *lazycomma = ""; - char buf[64]; - for ( content_type::const_iterator i = contents.begin(); - i < contents.end(); - i++ ) { - - snprintf( buf, sizeof buf, "%s0x%02x", lazycomma, static_cast(*i) ); - chars.append( buf ); - lazycomma = ", "; - } - chars.append( "]" ); - return chars; } + std::string chars( 1, '\'' ); + print_grapheme( chars ); + chars.append( "' [" ); + const char *lazycomma = ""; + char buf[64]; + for ( content_type::const_iterator i = contents.begin(); + i < contents.end(); + i++ ) { + + snprintf( buf, sizeof buf, "%s0x%02x", lazycomma, static_cast(*i) ); + chars.append( buf ); + lazycomma = ", "; + } + chars.append( "]" ); + return chars; } bool Cell::compare( const Cell &other ) const diff --git a/src/terminal/terminaluserinput.cc b/src/terminal/terminaluserinput.cc index 5973549..84d76f0 100644 --- a/src/terminal/terminaluserinput.cc +++ b/src/terminal/terminaluserinput.cc @@ -52,17 +52,14 @@ string UserInput::input( const Parser::UserByte *act, state = ESC; } return string( &act->c, 1 ); - break; case ESC: if ( act->c == 'O' ) { /* ESC O = 7-bit SS3 */ state = SS3; return string(); - } else { - state = Ground; - return string( &act->c, 1 ); } - break; + state = Ground; + return string( &act->c, 1 ); case SS3: state = Ground; @@ -75,12 +72,11 @@ string UserInput::input( const Parser::UserByte *act, char original_cursor[ 2 ] = { 'O', act->c }; return string( original_cursor, 2 ); } - break; + + default: + /* This doesn't handle the 8-bit SS3 C1 control, which would be + two octets in UTF-8. Fortunately nobody seems to send this. */ + assert( false ); + return string(); } - - /* This doesn't handle the 8-bit SS3 C1 control, which would be - two octets in UTF-8. Fortunately nobody seems to send this. */ - - assert( false ); - return string(); } diff --git a/src/util/locale_utils.cc b/src/util/locale_utils.cc index 41d5ee2..46697bd 100644 --- a/src/util/locale_utils.cc +++ b/src/util/locale_utils.cc @@ -51,9 +51,8 @@ const string LocaleVar::str( void ) const { if ( name.empty() ) { return string( "[no charset variables]" ); - } else { - return name + "=" + value; } + return name + "=" + value; } const LocaleVar get_ctype( void ) @@ -65,9 +64,8 @@ const LocaleVar get_ctype( void ) return LocaleVar( "LC_CTYPE", ctype ); } else if ( const char *lang = getenv( "LANG" ) ) { return LocaleVar( "LANG", lang ); - } else { - return LocaleVar( "", "" ); } + return LocaleVar( "", "" ); } const char *locale_charset( void ) diff --git a/src/util/swrite.cc b/src/util/swrite.cc index 64a772c..ada96f5 100644 --- a/src/util/swrite.cc +++ b/src/util/swrite.cc @@ -46,9 +46,8 @@ int swrite( int fd, const char *str, ssize_t len ) if ( bytes_written <= 0 ) { perror( "write" ); return -1; - } else { - total_bytes_written += bytes_written; } + total_bytes_written += bytes_written; } return 0;