Comparing version 0.8.0 to 0.8.1
@@ -39,6 +39,6 @@ 'use strict'; | ||
module.exports = function (length, resolvers) { | ||
var fn, cache, resolver, find, aset, rset, index, found, mfn; | ||
var fn, mfn, resolver, cache, find, save, clear | ||
, value; | ||
fn = callable(this); | ||
cache = []; | ||
if (isArray(length)) { | ||
@@ -52,3 +52,2 @@ resolvers = length; | ||
} | ||
if (resolvers != null) { | ||
@@ -62,55 +61,111 @@ resolvers = toArray(resolvers); | ||
find = function (args) { | ||
var limit, i, arg; | ||
cache = []; | ||
i = 0; | ||
aset = found = false; | ||
index = limit = (length === false) ? args.length : length; | ||
rset = cache; | ||
find = function (length, args) { | ||
var index = 0, rset = cache, i; | ||
if (limit === 0) { | ||
found = rset.hasOwnProperty(0); | ||
if (length === 0) { | ||
value = rset[length]; | ||
return rset.hasOwnProperty(length); | ||
} else if ((rset = rset[length])) { | ||
while (index < (length - 1)) { | ||
i = indexOf.call(rset[0], args[index]); | ||
if (i === -1) { | ||
return false; | ||
} | ||
rset = rset[1][i]; | ||
++index; | ||
} | ||
i = indexOf.call(rset[0], args[index]); | ||
if (i === -1) { | ||
return false; | ||
} | ||
value = rset[1][i]; | ||
return true; | ||
} | ||
return false; | ||
}; | ||
save = function (length, args, value) { | ||
var index = 0, rset = cache, i; | ||
if (length === 0) { | ||
rset[length] = value; | ||
} else { | ||
while (i !== limit) { | ||
if (!rset[index]) { | ||
rset = (rset[index] = [[args[i]], []]); | ||
index = 0; | ||
} else if ((index = | ||
indexOf.call((rset = rset[index])[0], args[i])) === -1) { | ||
index = rset[0].push(args[i]) - 1; | ||
found = false; | ||
} else { | ||
found = rset[1].hasOwnProperty(index); | ||
if (!rset[length]) { | ||
rset[length] = [[], []]; | ||
} | ||
rset = rset[length]; | ||
while (index < (length - 1)) { | ||
i = indexOf.call(rset[0], args[index]); | ||
if (i === -1) { | ||
i = rset[0].push(args[index]) - 1; | ||
rset[1].push([[], []]); | ||
} | ||
aset = rset[0]; | ||
rset = rset[1]; | ||
++i; | ||
rset = rset[1][i]; | ||
++index; | ||
} | ||
i = indexOf.call(rset[0], args[index]); | ||
if (i === -1) { | ||
i = rset[0].push(args[index]) - 1; | ||
} | ||
rset[1][i] = value; | ||
} | ||
}; | ||
clear = function (length, args) { | ||
var index = 0, rset = cache, i, path = []; | ||
if (length === 0) { | ||
delete rset[length]; | ||
} else if ((rset = rset[length])) { | ||
while (index < (length - 1)) { | ||
i = indexOf.call(rset[0], args[index]); | ||
if (i === -1) { | ||
return; | ||
} | ||
path.push(rset, i); | ||
rset = rset[1][i]; | ||
++index; | ||
} | ||
i = indexOf.call(rset[0], args[index]); | ||
if (i === -1) { | ||
return; | ||
} | ||
rset[0].splice(i, 1); | ||
rset[1].splice(i, 1); | ||
while (!rset[0].length && path.length) { | ||
i = path.pop(); | ||
rset = path.pop(); | ||
rset[0].splice(i, 1); | ||
rset[1].splice(i, 1); | ||
} | ||
} | ||
}; | ||
mfn = function () { | ||
var args, result; | ||
var args, alength; | ||
args = resolver ? resolver(arguments) : arguments; | ||
find(args); | ||
if (found) { | ||
result = rset[index]; | ||
alength = (length === false) ? args.length : length; | ||
if (find(alength, args)) { | ||
return value; | ||
} else { | ||
mfn.args = arguments; | ||
result = (rset[index] = apply.call(fn, this, args)); | ||
mfn.preventCache = false; | ||
value = apply.call(fn, this, args); | ||
if (!mfn.preventCache) { | ||
save(alength, args, value); | ||
} | ||
delete mfn.args; | ||
return value; | ||
} | ||
return result | ||
}; | ||
mfn.clearCache = function () { | ||
find(resolver ? resolver(arguments) : arguments); | ||
if (found) { | ||
if (aset) { | ||
aset.splice(index, 1); | ||
rset.splice(index, 1); | ||
} else { | ||
delete rset[index]; | ||
} | ||
} | ||
var args, alength; | ||
args = resolver ? resolver(arguments) : arguments; | ||
alength = (length === false) ? args.length : length; | ||
clear(alength, args); | ||
}; | ||
@@ -117,0 +172,0 @@ |
{ | ||
"name": "es5-ext", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "ECMAScript5 extensions", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
132384
3346
0