Ignore:
Timestamp:
Aug 30, 2018, 10:26:27 PM (3 years ago)
Author:
viala@…
Message:

Rewrite if-then-else return function into switch case.

For safety reason and performance:

1) Safety: GCC complain with a warning if you forgot an enum variant.
2) code-gen just outperform naive if-then-else.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/devices/dev_txt.c

    r492 r527  
    4949
    5050////////////////////////////////////////
    51 char * dev_txt_type_str( uint32_t type )
    52 {
    53     if     ( type == TXT_SYNC_WRITE ) return "TXT_SYNC_WRITE";
    54     else if( type == TXT_READ       ) return "TXT_READ";
    55     else if( type == TXT_WRITE      ) return "TXT_WRITE";
    56     else                              return "undefined";
     51const char * dev_txt_type_str( dev_txt_cmd_t type )
     52{
     53  switch (type) {
     54    case (TXT_SYNC_WRITE): return "TXT_SYNC_WRITE";
     55    case (TXT_READ):       return "TXT_READ";
     56    case (TXT_WRITE):      return "TXT_WRITE";
     57    default:               return "undefined";
     58  }
    5759}
    5860
Note: See TracChangeset for help on using the changeset viewer.