Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 2
    your code is not functionally the same - if matches is already true then the short circuit operator will prevent evaluation of field.contains(search). AFAIK the |= operator won't do that. Commented Apr 13, 2012 at 14:05
  • Which means my code is optimization of the original code Commented Apr 13, 2012 at 14:06
  • 1
    only if it's truly intended that .contains() is not called in those circumstances. Commented Apr 13, 2012 at 14:07
  • 1
    you mean if the .contains() method does not have side-effects Commented Apr 13, 2012 at 14:14
  • 1
    yeah, mostly - in this case it probably doesn't matter, but it's worth knowing that for boolean variables a |= func() is the same as a = a | func() which is not functionally the same as a = a || func(), even though the end result on a is the same. Commented Apr 13, 2012 at 16:26