Changeset 527 for trunk/kernel/fs


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/fs/vfs.c

    r492 r527  
    127127//////////////////////////////////////////////////////////////////////////////////////////
    128128
    129 char * vfs_inode_type_str( uint32_t type )
    130 {
    131     if     ( type == INODE_TYPE_FILE ) return "FILE";
    132     else if( type == INODE_TYPE_DIR  ) return "DIR ";
    133     else if( type == INODE_TYPE_FIFO ) return "FIFO";
    134     else if( type == INODE_TYPE_PIPE ) return "PIPE";
    135     else if( type == INODE_TYPE_SOCK ) return "SOCK";
    136     else if( type == INODE_TYPE_DEV  ) return "DEV ";
    137     else if( type == INODE_TYPE_SYML ) return "SYML";
    138     else                               return "undefined";
     129static const char * vfs_inode_type_str( vfs_inode_type_t type )
     130{
     131    switch ( type ) {
     132    case INODE_TYPE_FILE: return "FILE";
     133    case INODE_TYPE_DIR:  return "DIR ";
     134    case INODE_TYPE_FIFO: return "FIFO";
     135    case INODE_TYPE_PIPE: return "PIPE";
     136    case INODE_TYPE_SOCK: return "SOCK";
     137    case INODE_TYPE_DEV:  return "DEV ";
     138    case INODE_TYPE_SYML: return "SYML";
     139    default:              return "undefined";
     140    }
    139141}
    140142
Note: See TracChangeset for help on using the changeset viewer.