Created
October 5, 2012 14:52
-
-
Save niloc132/3840254 to your computer and use it in GitHub Desktop.
GWT 2.4.0 optimizations on JSNI source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Run with -Dgwt.jjs.traceMethods=Test.* to see optimization progress, then view | |
* compiled JS to see what other rewriting happens | |
* @author colin | |
* | |
*/ | |
public class Test implements EntryPoint { | |
public native void onModuleLoad() /*-{ | |
//Strings appearing multiple times will be interned | |
var a = {test:true}; | |
$wnd.alert(a["test"]); | |
$wnd.alert(a["test"]); | |
//using prompt to prevent excessive compilation | |
//notice in final output that local var is renamed | |
var str = $wnd.prompt("enter a string"); | |
//If blocks that wrap a simple statement will be turned into a ternary | |
if (str.length == 0) { | |
$wnd.alert("no string entered"); | |
} | |
//Unreferenced functions get compiled out | |
//and simple functions just get inlined | |
function willBeCalled() { | |
return "yes"; | |
} | |
function wontBeCalled() { | |
return "no"; | |
} | |
//Note, however, that this pure function won't be optimized out | |
willBeCalled(); | |
}-*/; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------------------------- | |
SCRIPT INITIAL: | |
--------------------------- | |
function $onModuleLoad(){ | |
var a = {test:true}; | |
$wnd.alert(a['test']); | |
$wnd.alert(a['test']); | |
var str = $wnd.prompt('enter a string'); | |
if (str.length == 0) { | |
$wnd.alert('no string entered'); | |
} | |
function willBeCalled(){ | |
return 'yes'; | |
} | |
function wontBeCalled(){ | |
return 'no'; | |
} | |
willBeCalled(); | |
} | |
--------------------------- | |
StaticEvalVisitor: | |
--------------------------- | |
function $onModuleLoad(){ | |
var a = {test:true}; | |
$wnd.alert(a['test']); | |
$wnd.alert(a['test']); | |
var str = $wnd.prompt('enter a string'); | |
str.length == 0 && $wnd.alert('no string entered'); | |
function willBeCalled(){ | |
return 'yes'; | |
} | |
function wontBeCalled(){ | |
return 'no'; | |
} | |
willBeCalled(); | |
} | |
--------------------------- | |
RemovalVisitor: | |
--------------------------- | |
function $onModuleLoad(){ | |
var a = {test:true}; | |
$wnd.alert(a['test']); | |
$wnd.alert(a['test']); | |
var str = $wnd.prompt('enter a string'); | |
str.length == 0 && $wnd.alert('no string entered'); | |
function willBeCalled(){ | |
return 'yes'; | |
} | |
willBeCalled(); | |
} | |
--------------------------- | |
StringVisitor: | |
--------------------------- | |
function $onModuleLoad(){ | |
var a = {test:true}; | |
$wnd.alert(a[$intern_22]); | |
$wnd.alert(a[$intern_22]); | |
var str = $wnd.prompt('enter a string'); | |
str.length == 0 && $wnd.alert('no string entered'); | |
function willBeCalled(){ | |
return 'yes'; | |
} | |
willBeCalled(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Ig() { | |
var a={test:true}; | |
$wnd.alert(a[hl]); | |
$wnd.alert(a[hl]); | |
var b=$wnd.prompt('enter a string'); | |
b.length==0&&$wnd.alert('no string entered'); | |
function c(){return 'yes'} | |
c() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment