Home > Back-end > Refer to the switch case alternatives
Refer to the switch case alternatives
Time:10-30
The service side, handle the client request, different request types corresponding to different functions, there are hundreds of types, feeling some of the switch case is a bit tedious, want to replace the function map, but under test, the function of map efficiency is lower than the switch case too much, later want to change the function array, made the subscript request type, but the request type is not continuous, don't know how to initialize the array before operation, all bosses still have what way?
CodePudding user response:
Change the function map to function hash
CodePudding user response:
The switch case compiler has been optimized is very good,
CodePudding user response:
Can you define a function pointer array, the type definition into the array in the following table, of course, in the following table and function need one to one correspondence, for your reference