Which is faster? Comparison or assignment?

前端 未结 12 1221
抹茶落季
抹茶落季 2020-12-05 04:16

I\'m doing a bit of coding, where I have to write this sort of code:

if( array[i]==false )
    array[i]=true;

I wonder if it should be re-w

12条回答
  •  青春惊慌失措
    2020-12-05 04:44

    Why would you even write the first version? What's the benefit of checking to see if something is false before setting it true. If you always are going to set it true, then always set it true.

    When you have a performance bottleneck that you've traced back to setting a single boolean value unnecessarily, come back and talk to us.

提交回复
热议问题