Skip to content

Commit

Permalink
Don't emit useless code for zero-arg operations/constructors
Browse files Browse the repository at this point in the history
Closes #34.
  • Loading branch information
domenic committed Apr 29, 2017
1 parent c2214f1 commit 4dd82b0
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,24 @@ module.exports.generateOverloadConversions = function (overloads, customTypes) {

const typeConversions = Overloads.proveSimiliarity(overloads);

str += `
const isAlwaysZeroArgs = !isVariadic && maxArguments === 0;
if (!isAlwaysZeroArgs) {
const extraClause = !isVariadic ? ` && i < ${maxArguments}` : ``;
str += `\n
const args = [];
for (let i = 0; i < arguments.length`;
if (!isVariadic) {
str += ` && i < ${maxArguments}`;
}
str += `; ++i) {
for (let i = 0; i < arguments.length${extraClause}; ++i) {
args[i] = utils.tryImplForWrapper(arguments[i]);
}`;
for (let i = 0; i < typeConversions.length; ++i) {
if (typeConversions[i] === null) {
continue;
}

const conv = module.exports.generateVarConversion(`args[${i}]`, typeConversions[i], maxConstructor.operation.arguments[i].extAttrs, customTypes);
Object.assign(requires, conv.requires);
str += conv.body;
for (let i = 0; i < typeConversions.length; ++i) {
if (typeConversions[i] === null) {
continue;
}

const conv = module.exports.generateVarConversion(`args[${i}]`, typeConversions[i], maxConstructor.operation.arguments[i].extAttrs, customTypes);
Object.assign(requires, conv.requires);
str += conv.body;
}
}
return {
requires,
Expand Down

0 comments on commit 4dd82b0

Please sign in to comment.