From baae9f8d544ab0eb62a2e61a0b5f347732c61eb3 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 22 Jul 2013 20:24:04 +0200 Subject: [PATCH] Define once --- lib/primitive.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/primitive.js b/lib/primitive.js index ec0c046..b9ae08b 100644 --- a/lib/primitive.js +++ b/lib/primitive.js @@ -8,7 +8,19 @@ var CustomError = require('es5-ext/lib/Error/custom') , serialize0 = function () { return ''; } , serialize1 = function (args) { return args[0]; } - , apply = Function.prototype.apply, call = Function.prototype.call; + , apply = Function.prototype.apply, call = Function.prototype.call + , serializeN; + +serializeN = function (args) { + var id = '', i, length = args.length; + if (length) { + id += args[i = 0]; + while (--length) id += '\u0001' + args[++i]; + } else { + id = '\u0002'; + } + return id; +}; module.exports = require('./_base')(function (conf, length) { var get, cache = conf.cache = {}, fn @@ -17,16 +29,7 @@ module.exports = require('./_base')(function (conf, length) { if (length === 1) { get = conf.get = serialize1; } else if (length === false) { - get = conf.get = function (args) { - var id = '', i, length = args.length; - if (length) { - id += args[i = 0]; - while (--length) id += '\u0001' + args[++i]; - } else { - id = '\u0002'; - } - return id; - }; + get = conf.get = serializeN; } else if (length) { get = conf.get = function (args) { var id = String(args[0]), i = 0, l = length;