I'm not sure if it's a missed optimization, but it seems the compiler
cannot optimize away getClass() for some reason.  If you do
LabelWidgetFactoryCms.class, then it'll optimize it away properly.  I
just checked & this behaviour is present in trunk as well:

public void onModuleLoad() {
   String nothing = this.getClass().getName() + "TEST";
}

In the compiled output, we see

function init(){
  !!$stats && $stats({moduleName:$moduleName, subSystem:'startup',
evtGroup:'moduleStartup', millis:(new Date()).getTime(),
type:'onModuleLoadStart', className:'org.gwt.client.Sample'});
  ($Sample(new Sample()) , Lorg_gwt_client_Sample_2_classLit).typeName + 'TEST';
}

but only if I have
    private final GreetingServiceAsync greetingService =
GWT.create(GreetingService.class);

declared as a field.  This problem also appears with OBF.

The problem appears to be that the compiler misses the optimization
On Sun, Apr 19, 2009 at 4:02 PM, Ed <[email protected]> wrote:
>
> Hi all,
>
> I was having a closer look and noticed (I am using gwt 1.5.2 still)
> that a variable and field that isn't used, isn't removed by the
> compiler if it has the class name as value.
>
> I did a little test with the following code.
> The example  class "LabelWidgetFactoryCms" contains the following
> fields and method:
> ----
>        private final Logger F_TEST1 =  FactoryLogger.getLogger(this.getClass
> ().getName() + "TEST1");
>        private final Logger F_TEST2 =  FactoryLogger.getLogger("TEST2");
>        private final String F_TEST3 =  "TEST3";
>        private final Logger F_TEST4 = new Logger(this.getClass().getName() +
> "TEST4");
>        private final Logger F_TEST5 = new Logger("TEST5");
>        private final String F_TEST6 = this.getClass().getName() + "TEST6";
>        private final String F_TEST7 = LabelWidgetFactoryCms.class.getName()
> + "TEST";
>
>
>        public Widget createTextWidget(final String key) {
>                Logger L_TEST1 =  
> FactoryLogger.getLogger(this.getClass().getName()
> + "TEST1");
>                Logger L_TEST2 =  FactoryLogger.getLogger("TEST2");
>                String L_TEST3 =  "TEST3";
>                Logger L_TEST4 = new Logger(this.getClass().getName() + 
> "TEST4");
>                Logger L_TEST5 = new Logger("TEST5");
>                String F_TEST6 = this.getClass().getName() + "TEST6";
>                String F_TEST7 = LabelWidgetFactoryCms.class.getName() + 
> "TEST7";
>                return createLabelWidget(findContentItem(key));
>        }
> ----
> Note:
> - FactoryLogger.getLogger(String) simple returns null.
> - Neither the fields or the variables aren't used.
>
>
> The result of compiler with mode PRETTY is the following:
> ----
> function $LabelWidgetFactoryCms_0(this$static, formatter,
> toolTipProvider){
>  getLogger(this$static.getClass$().typeName + 'TEST1');
>  this$static.getClass$().typeName + 'TEST4';
>  this$static.getClass$().typeName + 'TEST6';
>  return this$static;
> }
>
> ...
> function $createTextWidget(this$static, key){
>  getLogger(this$static.getClass$().typeName + 'TEST1');
>  this$static.getClass$().typeName + 'TEST4';
>  this$static.getClass$().typeName + 'TEST6';
>  return this$static.createLabelWidget($findContentItem_0(this$static,
> key));
> }
> ...
> ----
>
> Conclusion:
> - An unused field isn't removed when it includes the "this" class
> name.
> - An unused variable isn't removed when it included the "this" class
> name.
>
> Hmmmm interesting.... especially the difference getClass().getName()
> and LabelWidgetFactoryCms.class.getName()
> Is this a bug or expected behavior?
>
>
> -- Ed
>
>
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to