Skip to content

Codegen: Avoid useless zero subtraction in rest arguments #12188

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

Closed
subzey opened this issue Nov 11, 2016 · 1 comment
Closed

Codegen: Avoid useless zero subtraction in rest arguments #12188

subzey opened this issue Nov 11, 2016 · 1 comment
Labels
Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@subzey
Copy link
Contributor

subzey commented Nov 11, 2016

Currenty the function like this:

const foo = (...args: any[]): void => {
}

is transpiled into

var foo = function () {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i - 0] = arguments[_i];
    }
};

You may notice that zero subtraction in the args[_i-0] part is useless.

My proposal is to drop it and use just args[_i] in cases when the function signature consists only of spread.
This small change won't affect the generated code behavior, but would make it slightly more readable and compact.

You can preview the results here, and here's the proposed change

@DanielRosenwasser
Copy link
Member

Others may have a different opinion, but I think that we'd be okay with this. 👍

@DanielRosenwasser DanielRosenwasser added Help Wanted You can do this Suggestion An idea for TypeScript labels Nov 12, 2016
@mhegazy mhegazy added this to the TypeScript 2.2 milestone Nov 18, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Nov 18, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.2, TypeScript 2.1.3 Dec 5, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants