mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 20:37:48 +00:00
Add _.where fast path for the common use case or passing an object with one property.
Former-commit-id: dfb78f59ae22f3ccdd88d58cefdb8abcde58eda6
This commit is contained in:
17
build.js
17
build.js
@@ -102,7 +102,7 @@
|
|||||||
'compose': [],
|
'compose': [],
|
||||||
'contains': ['basicEach', 'getIndexOf', 'isString'],
|
'contains': ['basicEach', 'getIndexOf', 'isString'],
|
||||||
'countBy': ['createCallback', 'forEach'],
|
'countBy': ['createCallback', 'forEach'],
|
||||||
'createCallback': ['identity', 'isEqual', 'keys'],
|
'createCallback': ['identity', 'isEqual', 'isObject', 'keys'],
|
||||||
'debounce': ['isObject'],
|
'debounce': ['isObject'],
|
||||||
'defaults': ['createCallback', 'createIterator'],
|
'defaults': ['createCallback', 'createIterator'],
|
||||||
'defer': ['bind'],
|
'defer': ['bind'],
|
||||||
@@ -3657,6 +3657,15 @@
|
|||||||
' : (first ? find : filter)(collection, properties);',
|
' : (first ? find : filter)(collection, properties);',
|
||||||
'}'
|
'}'
|
||||||
].join('\n'));
|
].join('\n'));
|
||||||
|
|
||||||
|
// simplify `_.createCallback`
|
||||||
|
source = source.replace(matchFunction(source, 'createCallback'), function(match) {
|
||||||
|
return match
|
||||||
|
// remove unnecessary fast path
|
||||||
|
.replace(/^(( *)var props *=.+?),[\s\S]+?\n\2}/m, '$1;')
|
||||||
|
// remove `_.isEqual` use
|
||||||
|
.replace(/=.+?\bisEqual\((.+?), *(.+?),.+?\)/, '= $1 === $2');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// replace `_.zip`
|
// replace `_.zip`
|
||||||
if(!isLodash('zip')) {
|
if(!isLodash('zip')) {
|
||||||
@@ -3703,12 +3712,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove `_.isEqual` use from `createCallback`
|
|
||||||
if (!isLodash('where')) {
|
|
||||||
source = source.replace(matchFunction(source, 'createCallback'), function(match) {
|
|
||||||
return match.replace(/=.+?\bisEqual\((.+?), *(.+?),.+?\)/, '= $1 === $2');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// remove unused features from `createBound`
|
// remove unused features from `createBound`
|
||||||
if (_.every(['bindKey', 'partial', 'partialRight'], function(funcName) {
|
if (_.every(['bindKey', 'partial', 'partialRight'], function(funcName) {
|
||||||
return !_.contains(buildFuncs, funcName);
|
return !_.contains(buildFuncs, funcName);
|
||||||
|
|||||||
12
lodash.js
12
lodash.js
@@ -4762,10 +4762,20 @@
|
|||||||
return object[func];
|
return object[func];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var props = keys(func);
|
var props = keys(func),
|
||||||
|
key = props[0],
|
||||||
|
a = func[key];
|
||||||
|
|
||||||
|
if (props.length == 1 && a === a && !isObject(a)) {
|
||||||
|
return function(object) {
|
||||||
|
var b = object[key];
|
||||||
|
return a === b && (a !== 0 || (1 / a == 1 / b));
|
||||||
|
};
|
||||||
|
}
|
||||||
return function(object) {
|
return function(object) {
|
||||||
var length = props.length,
|
var length = props.length,
|
||||||
result = false;
|
result = false;
|
||||||
|
|
||||||
while (length--) {
|
while (length--) {
|
||||||
if (!(result = isEqual(object[props[length]], func[props[length]], indicatorObject))) {
|
if (!(result = isEqual(object[props[length]], func[props[length]], indicatorObject))) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user