Which is faster? Comparison or assignment?

前端 未结 12 1207
抹茶落季
抹茶落季 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:38

    It all depends on the data type. Assigning booleans is faster than first comparing them. But that may not be true for larger value-based datatypes.

提交回复
热议问题