Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Avoiding too many variables #2655

Open
akidee opened this issue Jan 18, 2021 · 0 comments
Open

Avoiding too many variables #2655

akidee opened this issue Jan 18, 2021 · 0 comments

Comments

@akidee
Copy link

akidee commented Jan 18, 2021

Input:

f = (function(a, b) {
  function id(s) {  return s; }
  return function m(c){
    let s = 0
    for (let i = 0; i < a; i++)
      s = s + c + id(b)
    return s
  }
})(4, 5)
__optimize(f);

Prepack output (with default settings in the REPL):

(function () {
  var _$8 = this;

  var _1 = function (c) {
    var _$0 = 0 + c;

    var _$1 = _$0 + 5;

    var _$2 = _$1 + c;

    var _$3 = _$2 + 5;

    var _$4 = _$3 + c;

    var _$5 = _$4 + 5;

    var _$6 = _$5 + c;

    var _$7 = _$6 + 5;

    return _$7;
  };

  _$8.f = _1;
}).call(this);

How can I avoid this many variables being defined?

@akidee akidee changed the title No loop unrolling Avoiding too many variables Jan 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant