Changeset 527 for trunk/kernel/devices


Ignore:
Timestamp:
Aug 30, 2018, 10:26:27 PM (6 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.

Location:
trunk/kernel/devices
Files:
2 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
  • trunk/kernel/devices/dev_txt.h

    r457 r527  
    7878 *****************************************************************************************/
    7979
    80 enum
     80typedef enum
    8181{
    8282    TXT_READ       = 0,
    8383    TXT_WRITE      = 1,
    8484    TXT_SYNC_WRITE = 2,
    85 };
     85} dev_txt_cmd_t;
    8686
    8787typedef struct txt_command_s
     
    113113 * @ type     : command type (TXT_READ / TXT_WRITE / TXT_SYNC_WRITE)
    114114 *****************************************************************************************/
    115 char * dev_txt_type_str( uint32_t type );
     115const char * dev_txt_type_str( dev_txt_cmd_t type );
    116116
    117117/******************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.