Skip to content

Commit

Permalink
cleanup core object init argument passing
Browse files Browse the repository at this point in the history
- don't allocate new array if no arguments exist
- don't do costly apply, if there are not multiple (or any) arguments to apply to

test run stats:

1 arguments 10153
2 arguments   490
3 arguments     0
4 arguments     5

(yes apps may use this differently, but ultimately the 1 argument case is the most common, and most hot-paths are in ember-corec)
  • Loading branch information
stefanpenner committed Nov 12, 2014
1 parent facd8cc commit 1e2a8fd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/ember-runtime/lib/system/core_object.js
Expand Up @@ -170,16 +170,22 @@ function makeCtor() {
}
}
}

finishPartial(this, m);

var length = arguments.length;
var args = new Array(length);
for (var x = 0; x < length; x++) {
args[x] = arguments[x];

if (length === 0) {
this.init();
} else if (length === 1) {
this.init(arguments[0]);
} else {
this.init.apply(this, arguments);
}
apply(this, this.init, args);

m.proto = proto;
finishChains(this);
sendEvent(this, "init");
sendEvent(this, 'init');
};

Class.toString = Mixin.prototype.toString;
Expand Down

0 comments on commit 1e2a8fd

Please sign in to comment.