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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/chdev.c

    r516 r527  
    5757char * chdev_func_str( uint32_t func_type )
    5858{
    59         if     ( func_type == DEV_FUNC_RAM ) return "RAM";
    60         else if( func_type == DEV_FUNC_ROM ) return "ROM";
    61         else if( func_type == DEV_FUNC_FBF ) return "FBF";
    62         else if( func_type == DEV_FUNC_IOB ) return "IOB";
    63         else if( func_type == DEV_FUNC_IOC ) return "IOC";
    64         else if( func_type == DEV_FUNC_MMC ) return "MMC";
    65         else if( func_type == DEV_FUNC_DMA ) return "DMA";
    66         else if( func_type == DEV_FUNC_NIC ) return "NIC";
    67         else if( func_type == DEV_FUNC_TIM ) return "TIM";
    68         else if( func_type == DEV_FUNC_TXT ) return "TXT";
    69         else if( func_type == DEV_FUNC_ICU ) return "ICU";
    70         else if( func_type == DEV_FUNC_PIC ) return "PIC";
    71     else                                 return "undefined";
     59  switch ( func_type ) {
     60    case DEV_FUNC_RAM: return "RAM";
     61    case DEV_FUNC_ROM: return "ROM";
     62    case DEV_FUNC_FBF: return "FBF";
     63    case DEV_FUNC_IOB: return "IOB";
     64    case DEV_FUNC_IOC: return "IOC";
     65    case DEV_FUNC_MMC: return "MMC";
     66    case DEV_FUNC_DMA: return "DMA";
     67    case DEV_FUNC_NIC: return "NIC";
     68    case DEV_FUNC_TIM: return "TIM";
     69    case DEV_FUNC_TXT: return "TXT";
     70    case DEV_FUNC_ICU: return "ICU";
     71    case DEV_FUNC_PIC: return "PIC";
     72    default:           return "undefined";
     73    }
    7274}
    7375
Note: See TracChangeset for help on using the changeset viewer.