Add duplicate memoization prevention

This commit is contained in:
Mariusz Nowak
2014-09-22 16:20:00 +02:00
parent 67bd739655
commit a363f22d8b

View File

@@ -14,6 +14,7 @@ var customError = require('es5-ext/error/custom')
, resolveNormalize = require('./resolve-normalize')
, slice = Array.prototype.slice, defineProperties = Object.defineProperties
, hasOwnProperty = Object.prototype.hasOwnProperty
, clearOnDispose;
clearOnDispose = function () {
@@ -26,6 +27,10 @@ module.exports = function (memoize) {
var map, length, options = normalizeOpts(arguments[1]), memoized, resolve, normalizer;
callable(fn);
// Do not memoize already memoized function
if (hasOwnProperty.call(fn, '__memoized__') && !options.force) return fn;
length = resolveLength(options.length, fn.length, options.async && extensions.async);
options.length = length ? length - 1 : 0;
map = new WeakMap();