This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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/





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]