PreviousNext
Switch instead of if
Help > Appendix > Code Optimization > Switch instead of if

FLASH-                        RAM                Speed+

 

CC5X generates more efficient code in the case of the switch when an expression value is compared to the more than usually 2 constant values.

 

if ( byte == 1 || byte == 3 )

  _LEDR = 1;

else if ( byte == 7 || byte == 13 )

  _LEDR = 0;

switch( byte )

{

case 1:

case 3:

  _LEDG = 1;

  break;

 

case 7:

case 13:

  _LEDG = 0;

  break;

}