Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize output of rest param transformer #2116

Open
arv opened this issue May 14, 2016 · 0 comments
Open

Optimize output of rest param transformer #2116

arv opened this issue May 14, 2016 · 0 comments

Comments

@arv
Copy link
Collaborator

arv commented May 14, 2016

In a strict function if all accesses of the rest param is rest[expr] and rest.length we could generate code that only references arguments.

For example:

'use strict';
function f(x, ...xs) {
  for (let i = 0; i < xs.length; i++) {
    print(xs[i]);
  }
}

Today we compile that into:

'use strict';
function f(x) {
  for (var xs = [],
      $__0 = 1; $__0 < arguments.length; $__0++)
    xs[$__0 - 1] = arguments[$__0];
  for (var i = 0; i < xs.length; i++) {
    print(xs[i]);
  }
}

But we could compile it into:

'use strict';
function f(x) {
  for (var i = 0; i < arguments.length - 1; i++) {
    print(arguments[i + 1]);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant