Christian Thalinger wrote:
I don't know if this is performance critical code or is used very often,
but this seems to be a special case and i'd suggest something like:

public void write (int oneByte) throws IOException
{
  try {
    out.write(oneByte);
    return;
  } catch (NullPointerException e) {
    throw new IOException("Bad file descriptor");
  }
}

I'll not win a beautiful-code prize, but will be compiled to the fastest
code.

That's getting into the micro-optimzation realm, which is
fraught with danger and mistaken assumptions :-) E.g., on
some machines the time overhead of setting up a try/catch in
a method that wouldn't otherwise have one is higher than
the single comparison required to test for null. In particular,
any interpreter is going to have to test for null anyway,
so the second time it's already in cache, blah blah, etc.

Not to mention that the space overhead of a try/catch (vs. none)
will probably be higher too. So IMHO it's better to avoid
too much of this kind of thing (unless it actually makes the
source code clearer (don't think so in this case)).

Apologies for the minor IMHO rant.. :-)

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com


_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to