Is the conditional operator slow?

前端 未结 8 1956
广开言路
广开言路 2020-12-03 06:59

I was looking at some code with a huge switch statement and an if-else statement on each case and instantly felt the urge to optimize. As a good developer always should do I

8条回答
  •  不知归路
    2020-12-03 07:51

    Assuming you're concerned about the performance of that method (and if you're not, why bother posting it?), you should consider storing the char values in an array and converting the Key values to an index into the array.

提交回复
热议问题