groovy/groovy-core — pull request #86 by adriannistor (2012-12-18 18:02:29+00:00)
Title: GROOVY-5853: wasted work in "DefaultGrailsDomainClassInjector.implementsMethod"

Pull request for http://jira.codehaus.org/browse/GROOVY-5853

The problem appears in version 2.0.5 and in revision 4cf5263..

In method "DefaultGrailsDomainClassInjector.implementsMethod", in the
loop over "methods", the statement
"boolean methodMatch = mn.getName().equals(methodName) && isZeroArg"
should be
"boolean methodMatch = isZeroArg && mn.getName().equals(methodName)".
The second statement avoids comparing strings when "isZeroArg" is
"false".

The code can be made even shorter and faster by having a fast exit (by
pulling "isZeroArg" out of the loop) at the beginning of the method
body; this avoids the entire method computation. While the resulting
code is more compact than the original, the patch itself is a bit
larger (deletes 3 lines, adds 2). I attached this patch
(patchFull.diff) in the GROOVY-5853 JIRA report.