[gwt-contrib] Re: NewParenthesisRemovalOptimization

2009-07-02 Thread Ray Cromwell
On Thu, Jul 2, 2009 at 3:23 PM, Ian Petersen  wrote:

>
>
> Had a pretty random thought on the way to the bathroom: "new
> Foo().bar()" is equivalent to "(new Foo).bar()".  Is it equivalent to
> "new Foo.bar()"?  I would expect not.  Does that matter?  Does the
> compiler generate code that looks like "new Foo.bar()" with your patch
> in place?
>

The compiler (the code-gen JsToStringGenerator part) has a precedence
checking routine for handling this. If you do new Foo().bar, if will replace
it with (new Foo).bar. Since the JsInvocation ("new" operator) is supposed
to bind tighter with the JsNameRef in the constructor expression than the
'bar' name ref is to the "new".


-Ray


>
> Ian
>
> >
>

--~--~-~--~~~---~--~~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~--~~~~--~~--~--~---



[gwt-contrib] Re: NewParenthesisRemovalOptimization

2009-07-02 Thread Ian Petersen

On Thu, Jul 2, 2009 at 12:14 PM,  wrote:
> Reviewers: scottb,
>
> Description:
> This patch removes trailing parenthesis from Javascript 'new' operators
> if there
> are no constructor arguments.
>
> new Foo() -> new Foo
>
> Now with fixes based on Scott's review, as well as some inline comments
> in case future archaeologists after the apocalypse discover this code
> and want to know the motivation.

Had a pretty random thought on the way to the bathroom: "new
Foo().bar()" is equivalent to "(new Foo).bar()".  Is it equivalent to
"new Foo.bar()"?  I would expect not.  Does that matter?  Does the
compiler generate code that looks like "new Foo.bar()" with your patch
in place?

Ian

--~--~-~--~~~---~--~~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~--~~~~--~~--~--~---



[gwt-contrib] Re: NewParenthesisRemovalOptimization

2009-07-02 Thread rice


http://gwt-code-reviews.appspot.com/47808/diff/1/2
File dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
(right):

http://gwt-code-reviews.appspot.com/47808/diff/1/2#newcode587
Line 587: // replaced with "new Constructor" with no parenthesis
parentheses (plural)

http://gwt-code-reviews.appspot.com/47808/diff/1/2#newcode588
Line 588: if (x.getArguments().size() > 0) {
Possible to call getArguments only once?

http://gwt-code-reviews.appspot.com/47808

--~--~-~--~~~---~--~~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~--~~~~--~~--~--~---



[gwt-contrib] Re: NewParenthesisRemovalOptimization

2009-07-02 Thread Joel Webber
W00t, thanks Ray! I've been meaning to do something about this list of
peephole optimizations for some time, but you're much more likely to be able
to get through them quickly than I am. The good news is that going through
the entire list gives a 15-20% code size reduction on Hello (roughly
measured by hand). And I don't think any of them are complex.

On Wed, Jul 1, 2009 at 8:10 PM, Scott Blum  wrote:

> LGTM, but only if you fix the darn for-each using Object var!
>
> On Wed, Jul 1, 2009 at 7:50 PM,  wrote:
>
>> Reviewers: scottb,
>>
>> Description:
>> This patch removes trailing parenthesis from Javascript 'new' operators
>> if there are no constructor arguments.
>>
>> new Foo() -> new Foo
>>
>>
>> Please review this at http://gwt-code-reviews.appspot.com/49804
>>
>> Affected files:
>>  dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
>>
>>
>> Index: dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
>> ===
>> --- dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
>> (revision 5638)
>> +++ dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
>> (working copy)
>> @@ -583,16 +583,18 @@
>>   _rparen();
>> }
>>
>> -_lparen();
>> -boolean sep = false;
>> -for (Object element : x.getArguments()) {
>> -  JsExpression arg = (JsExpression) element;
>> -  sep = _sepCommaOptSpace(sep);
>> -  _parenPushIfCommaExpr(arg);
>> -  accept(arg);
>> -  _parenPopIfCommaExpr(arg);
>> +if (x.getArguments().size() > 0) {
>> +  _lparen();
>> +  boolean sep = false;
>> +  for (Object element : x.getArguments()) {
>> +JsExpression arg = (JsExpression) element;
>> +sep = _sepCommaOptSpace(sep);
>> +_parenPushIfCommaExpr(arg);
>> +accept(arg);
>> +_parenPopIfCommaExpr(arg);
>> +  }
>> +  _rparen();
>> }
>> -_rparen();
>>
>> return false;
>>   }
>>
>>
>>
>
> >
>

--~--~-~--~~~---~--~~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~--~~~~--~~--~--~---



[gwt-contrib] Re: NewParenthesisRemovalOptimization

2009-07-01 Thread Scott Blum
LGTM, but only if you fix the darn for-each using Object var!

On Wed, Jul 1, 2009 at 7:50 PM,  wrote:

> Reviewers: scottb,
>
> Description:
> This patch removes trailing parenthesis from Javascript 'new' operators
> if there are no constructor arguments.
>
> new Foo() -> new Foo
>
>
> Please review this at http://gwt-code-reviews.appspot.com/49804
>
> Affected files:
>  dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
>
>
> Index: dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
> ===
> --- dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
> (revision 5638)
> +++ dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
> (working copy)
> @@ -583,16 +583,18 @@
>   _rparen();
> }
>
> -_lparen();
> -boolean sep = false;
> -for (Object element : x.getArguments()) {
> -  JsExpression arg = (JsExpression) element;
> -  sep = _sepCommaOptSpace(sep);
> -  _parenPushIfCommaExpr(arg);
> -  accept(arg);
> -  _parenPopIfCommaExpr(arg);
> +if (x.getArguments().size() > 0) {
> +  _lparen();
> +  boolean sep = false;
> +  for (Object element : x.getArguments()) {
> +JsExpression arg = (JsExpression) element;
> +sep = _sepCommaOptSpace(sep);
> +_parenPushIfCommaExpr(arg);
> +accept(arg);
> +_parenPopIfCommaExpr(arg);
> +  }
> +  _rparen();
> }
> -_rparen();
>
> return false;
>   }
>
>
>

--~--~-~--~~~---~--~~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~--~~~~--~~--~--~---



[gwt-contrib] Re: NewParenthesisRemovalOptimization

2009-07-01 Thread Ray Cromwell
Compiling the Mail application removes ~860 bytes off the smallest
permutation, compiling Showcase removes about 1.6k off the largest
permutation.
-Ray


On Wed, Jul 1, 2009 at 4:50 PM,  wrote:

> Reviewers: scottb,
>
> Description:
> This patch removes trailing parenthesis from Javascript 'new' operators
> if there are no constructor arguments.
>
> new Foo() -> new Foo
>
>
> Please review this at http://gwt-code-reviews.appspot.com/49804
>
> Affected files:
>  dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
>
>
> Index: dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
> ===
> --- dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
> (revision 5638)
> +++ dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
> (working copy)
> @@ -583,16 +583,18 @@
>   _rparen();
> }
>
> -_lparen();
> -boolean sep = false;
> -for (Object element : x.getArguments()) {
> -  JsExpression arg = (JsExpression) element;
> -  sep = _sepCommaOptSpace(sep);
> -  _parenPushIfCommaExpr(arg);
> -  accept(arg);
> -  _parenPopIfCommaExpr(arg);
> +if (x.getArguments().size() > 0) {
> +  _lparen();
> +  boolean sep = false;
> +  for (Object element : x.getArguments()) {
> +JsExpression arg = (JsExpression) element;
> +sep = _sepCommaOptSpace(sep);
> +_parenPushIfCommaExpr(arg);
> +accept(arg);
> +_parenPopIfCommaExpr(arg);
> +  }
> +  _rparen();
> }
> -_rparen();
>
> return false;
>   }
>
>
>

--~--~-~--~~~---~--~~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~--~~~~--~~--~--~---