svn commit: r227812 - head/lib/libc/string

David Chisnall theraven at FreeBSD.org
Tue Nov 22 14:20:22 UTC 2011


On 22 Nov 2011, at 11:21, Bruce Evans wrote:

> If this optimization were any good, then the compiler would already do
> it.  In fact, gcc-4.2.1 already does it -- the reverse of it -- it rewrites:
> 
> 	"if ((i == 0) | (j == 0)) return; test();"
> 
> into:
> 
> 	"if (i == 0 || j == 0) return; test();"

In general, I prefer | in cases where execution order does not matter because it frees the compiler up to insert branches or not, depending on which is more efficient for the target.  

In this case, either | or || is fine, because neither reads any memory or has side effects so | and || are equivalent to the compiler, but the use of | tells a human reading the code that the order is unimportant.  

David


More information about the svn-src-head mailing list