Is the conditional operator slow?

前端 未结 8 1920
广开言路
广开言路 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

    I don't have VS to hand but surely there's a simple built-in way to get the key as a character? Something like a toString method so you can replace that monstrous switch with this:

    if (shift)
      return inKey.toString().toUppercase();
    else
      return inKey.toString().toLowercase();
    
    0 讨论(0)
  • 2020-12-03 07:52

    I would choose the third option only because it is more readable/maintainable. I bet this code isn't the bottleneck of your application performance.

    0 讨论(0)
提交回复
热议问题