R
Red Orchid
In JavaMail 1.3.2 Source Code,
there are the three 'checkAscii(...)' methods.
All of them have the variable 'int ascii'.
For details, the following is source of
'checkAscii(byte[] b)':
<quote>
static int checkAscii(byte[] b) {
int ascii = 0, non_ascii = 0;
for (int i=0; i < b.length; i++) {
// ...
if (nonascii(b & 0xff)) // non-ascii
non_ascii++;
else
ascii++; // <-- #1
}
if (non_ascii == 0)
return ALL_ASCII;
if (ascii > non_ascii)
return MOSTLY_ASCII;
return MOSTLY_NONASCII;
}
</quote>
Do you think that the above code is good or not bad
because #1 is trivial and the readability is good or ..?
I think that the above code is bad because #1 is
needless and is not trivial. For example, MIME
message's size can be large if it has attachments.
Java do not have the keywork 'register' of c/c++.
I think that the following is better than the above code.
<code>
static int checkAscii(byte[] b) {
int non_ascii = 0;
for (int i = 0; i < b.length; i++) {
if (nonascii(b & 0xff)) {
non_ascii++;
}
}
if (non_ascii == 0) {
return ALL_ASCII;
}
if ( non_ascii < (b.length >> 1) ) {
return MOSTLY_ASCII;
}
return MOSTLY_NONASCII;
}
</code>
What is your opinion ?
Thanks.
there are the three 'checkAscii(...)' methods.
All of them have the variable 'int ascii'.
For details, the following is source of
'checkAscii(byte[] b)':
<quote>
static int checkAscii(byte[] b) {
int ascii = 0, non_ascii = 0;
for (int i=0; i < b.length; i++) {
// ...
if (nonascii(b & 0xff)) // non-ascii
non_ascii++;
else
ascii++; // <-- #1
}
if (non_ascii == 0)
return ALL_ASCII;
if (ascii > non_ascii)
return MOSTLY_ASCII;
return MOSTLY_NONASCII;
}
</quote>
Do you think that the above code is good or not bad
because #1 is trivial and the readability is good or ..?
I think that the above code is bad because #1 is
needless and is not trivial. For example, MIME
message's size can be large if it has attachments.
Java do not have the keywork 'register' of c/c++.
I think that the following is better than the above code.
<code>
static int checkAscii(byte[] b) {
int non_ascii = 0;
for (int i = 0; i < b.length; i++) {
if (nonascii(b & 0xff)) {
non_ascii++;
}
}
if (non_ascii == 0) {
return ALL_ASCII;
}
if ( non_ascii < (b.length >> 1) ) {
return MOSTLY_ASCII;
}
return MOSTLY_NONASCII;
}
</code>
What is your opinion ?
Thanks.