> In JavaMail 1.3.2 Source Code,
> there are the three 'checkAscii(...)' methods.
> All of them have the variable 'int ascii'.
> if (nonascii(b[i] & 0xff)) // non-ascii
> non_ascii++;
> else
> ascii++; // <-- #1
> Do you think that the above code is good or not bad
> because #1 is trivial and the readability is good or ..?
I agree that keeping count of the ascii characters as well as the non-ascii is
needless work, and mildly obfucating. I certainly wouldn't have programmed it
that way. But:
> if ( non_ascii < (b.length >> 1) ) {
> return MOSTLY_ASCII;
Is even more obfuscatory. There can be no possible need for bit-twiddling here
to "gain speed" (even if we accept that this code might be used in a
speed-critcal context[*]) since the comparison is happening outside the inner
loop.
-- chris
([*] which seems unlikely to me -- or rather, it's hard to imagine a context
where this code would be the dominating factor)