13 May 2004 20:52
Re: [groovy-dev] Optimizing Scripts (just an Idea)
On 13 May 2004, at 16:00, bing ran wrote:
> Hi Thomas,
>
> This is what really happens for your two lines of code:
>
> package bran.groovy;
>
> import groovy.lang.Binding;
> import groovy.lang.Script;
> import org.codehaus.groovy.runtime.InvokerHelper;
>
> public class println extends Script {
>
> public println() {
> }
>
> public println(Binding binding) {
> super.setBinding(binding);
> }
>
> public static void main(String args[]) {
> Object __temp1 = ((Object) ({
> bran.groovy.println.class, args
> }));
>
> InvokerHelper.invokeMethod(org.codehaus.groovy.runtime.InvokerHelper.cl
> ass,
> "runScript", __temp1);
> }
>
> public Object run() {
> InvokerHelper.setGroovyObjectProperty(new Integer(3), this,
> "x");
> Object __temp2 = ((Object) ({
> InvokerHelper.getGroovyObjectProperty(this, "x")
> }));
> return InvokerHelper.invokeMethod(this, "println", __temp2);
> }
Note we can optimise the above 3 calls slightly, since all of these
operations operate on 'this'. So rather than calling a static helper
method, we could just invoke the methods directly (since this is-a
GroovyObject)
e.g. this method could be
public Object run() {
setProperty("x", new Integer(3))
Object __temp2 = getPorperty("x")
return invokeMethod("println", __temp2)
}
Though maybe hotspot is smart enough to figure that out?
Finally we could use class static constants for the numbers. e.g.
setProperty("x", _constant_1)
private static final Integer constant_1 = new Integer(3);
James
-------
http://radio.weblogs.com/0112098/
RSS Feed