(1) inline functions
(2) Replace arrays with pointers
(3) do not define unused return values
(4) use register variables
(5) use the auto-increment and auto-subtraction Operators
(6) Reduce function call Parameters
(7) Case sorting based on the frequency of occurrence in the switch statement
(8) convert large switch statements into nested switch statements (also based on the Occurrence Frequency)
(9) If a switch has a lot of work to do in each case, it is more effective to replace the entire switch statement with a table pointing to the function pointer, for example, the following switch statement has three conditions:
Enum msgtype {msg1, msg2, msg3}
Switch (receivemessage ()
{
Case msg1;
......
Case msg2;
.....
Case msg3;
.....
}
To improve the execution speed, use the following sectionCodeTo replace the preceding switch statement.
/* Preparations */
Int handlemsg1 (void );
Int handlemsg2 (void );
Int handlemsg3 (void );
/* Create a function pointer array */
INT (* msgfunction []) () = {handlemsg1, handlemsg2, handlemsg3 };
/* Replace the switch statement with the more effective code below */
Status = msgfunction [receivemessage ()] ();
(10) avoid using the expensive features of c ++.
Adding a class does not affect the code size orProgram. However, the multiple inheritance, virtual base class, template, exception handling, and running type recognition of C ++ have a negative impact on the code size and efficiency, therefore, exercise caution when using some features of C ++. You can perform some experiments to see their impact on the application.