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

Allow assert to be optimized #71

Merged
merged 3 commits into from Aug 4, 2014
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/index.js
Expand Up @@ -413,7 +413,11 @@ exports.assert = function (condition /*, msg1, msg2, msg3 */) {
return;
}

var msgs = Array.prototype.slice.call(arguments, 1);
var msgs = [];
for (var i = 1, il = arguments.length; i < il; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure about this change. I have no doubt this is faster and can be optimized, but there is probably a reason no one really does it this way and always uses the Array.prototype.slice.call trick.

Check out this implementation. https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#32-leaking-arguments. That looks like the way to go to me personally if we are trying to squeeze optimizations.

msgs.push(arguments[i]);
}

msgs = msgs.map(function (msg) {

return typeof msg === 'string' ? msg : msg instanceof Error ? msg.message : JSON.stringify(msg);
Expand Down