Patch: Remove exception catching from normal path in Arrays.equals.

Mohan Embar gnustuff@thisiscool.com
Sat Sep 6 16:17:00 GMT 2003


Tom,

While we're on this subject, there are myriad places (natClass.cc,
natRuntime.cc, natArray.cc, natConstructor.cc, natField.cc, natMethod.cc,
natResourceBundle.cc) where gnu.gcj.StackTrace is being used
like this (example from natArray.cc):

try
{
  for (int i = 1; !caller; i++)
    {
      caller = t->classAt (i);
    }
  caller_loader = caller->getClassLoaderInternal();
}
catch (::java::lang::ArrayIndexOutOfBoundsException *e)
{
}

Unless I'm not understanding something correctly, it seems to me that this
variant is much easier to read:

for (int i = 1; !caller && i < t->length (); ++i)
  {
    caller = t->classAt (i);
  }
if (caller)
  caller_loader = caller->getClassLoaderInternal ();

And this one would be even better:

Class* caller = t->tryTofindFirstNonNullClassStartingAtIndex (1);
if (caller)
  caller_loader = caller->getClassLoaderInternal ();

...where tryTofindFirstNonNullClassStartingAtIndex, a new method of
StackTrace, is replaced by a better name (I'm bad at names).

I've pondered submitting a patch for this, but haven't, because
I don't think that the code in question suffers from bad performance.
The patch would be mostly aesthetic.

Should I submit a patch anyway? Or is this not worth it?

-- Mohan
http://www.thisiscool.com/
http://www.animalsong.org/






More information about the Java-patches mailing list