Which is faster? Comparison or assignment?

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

    This isn't just premature optimization, this is micro-optimization, which is an irrelevant distraction.

    Assuming your array is of boolean type then your comparison is unnecessary, which is the only relevant observation.

提交回复
热议问题