Skip to content

JS should optimize (a=b, a) expressions, rewrite as a=b #10399

Description

@niloc132

The GWT AST JMultiExpression and JS AST JsBinaryOperation with COMMA are used to condense simple statements into an expression, enabling further inlining work. However, from time to time these can emit code like (a=<expr>, a) in the JS output, which could be optimized to simply (a=<expr>). The value of both expressions is the same, with a few bytes saved.

This is a fairly easy change for JsStaticEval.trySimplifyComma, with a few simple improvements as a result.

As an example, SimpleEventBus gets this small improvement in the showcase:

   if (!event) {
     throw toJs(new NullPointerException('Cannot fire null event'));
   }
   try {
     ++this$static.firingDepth;
-    handlers = (directHandlers = $getHandlerList(this$static, event.getAssociatedType(), null) , directHandlers);
+    handlers = directHandlers = $getHandlerList(this$static, event.getAssociatedType(), null);
     causes = null;
     it = this$static.isReverseOrder?handlers.listIterator(handlers.size()):handlers.listIterator();
     while (this$static.isReverseOrder?it.hasPrevious():it.hasNext()) {
       handler = this$static.isReverseOrder?it.previous():it.next();
       try {

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions