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/kern/thread.c

    r518 r527  
    5353// This function returns a printable string for the thread type.
    5454//////////////////////////////////////////////////////////////////////////////////////
    55 char * thread_type_str( uint32_t type )
    56 {
    57     if     ( type == THREAD_USER   ) return "USR";
    58     else if( type == THREAD_RPC    ) return "RPC";
    59     else if( type == THREAD_DEV    ) return "DEV";
    60     else if( type == THREAD_IDLE   ) return "IDL";
    61     else                             return "undefined";
     55const char * thread_type_str( thread_type_t type )
     56{
     57  switch ( type ) {
     58  case THREAD_USER:   return "USR";
     59  case THREAD_RPC:    return "RPC";
     60  case THREAD_DEV:    return "DEV";
     61  case THREAD_IDLE:   return "IDL";
     62  default:            return "undefined";
     63  }
    6264}
    6365
Note: See TracChangeset for help on using the changeset viewer.