Cleanup isLaziable and getFuncNames.

This commit is contained in:
jdalton
2015-03-20 09:24:56 -07:00
parent 002caceb05
commit eab18df403

View File

@@ -3389,10 +3389,8 @@
if (typeof func != 'function') { if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT); throw new TypeError(FUNC_ERROR_TEXT);
} }
var funcName = wrapper ? null : getFuncName(func); var funcName = wrapper ? '' : getFuncName(func);
if (funcName && (funcName == 'wrapper' || isLaziable(func))) { wrapper = funcName == 'wrapper' ? new LodashWrapper([]) : wrapper;
wrapper = new LodashWrapper([]);
}
} }
index = wrapper ? -1 : length; index = wrapper ? -1 : length;
while (++index < length) { while (++index < length) {
@@ -4104,28 +4102,33 @@
return false; return false;
} }
var getFuncName = !support.funcNames ? constant('') : function(func) { var getFuncName = (function() {
var result = func.name; if (!support.funcNames) {
if (result) { return constant('');
return realNames[result] || result;
} }
var anons = realNames[result]; if (constant.name == 'constant') {
if (!anons) { return baseProperty('name');
return result;
} }
var length = anons.length; return function(func) {
var result = func.name,
array = realNames[result],
length = array ? array.length : 0;
while (length--) { while (length--) {
var anon = anons[length]; var data = array[length],
if (anon.func == func) { otherFunc = data.func;
return anon.name;
if (otherFunc == null || otherFunc == func) {
return data.name;
} }
} }
return result; return result;
}; };
}());
function isLaziable(func) { function isLaziable(func) {
var funcName = getFuncName(func); var funcName = getFuncName(func);
return funcName ? func === lodash[funcName] : false; return !!funcName && func === lodash[funcName] && funcName in LazyWrapper.prototype;
} }
/** /**
@@ -11943,20 +11946,17 @@
}; };
}); });
if (support.funcNames) { // Map minified function names to their real names.
realNames[createHybridWrapper(null, BIND_KEY_FLAG).name] = 'wrapper';
baseForOwn(LazyWrapper.prototype, function(func, methodName) { baseForOwn(LazyWrapper.prototype, function(func, methodName) {
var lodashFunc = lodash[methodName], var lodashFunc = lodash[methodName],
key = lodashFunc.name; key = lodashFunc.name,
names = realNames[key] || (realNames[key] = []);
if (key) { names.push({ 'name': methodName, 'func': lodashFunc });
realNames[key] = methodName;
} else {
var anons = realNames[key] || (realNames[key] = []);
anons.push({ 'name': methodName, 'func': lodashFunc });
}
}); });
}
realNames[createHybridWrapper(null, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': null }];
// Add functions to the lazy wrapper. // Add functions to the lazy wrapper.
LazyWrapper.prototype.clone = lazyClone; LazyWrapper.prototype.clone = lazyClone;
LazyWrapper.prototype.reverse = lazyReverse; LazyWrapper.prototype.reverse = lazyReverse;