mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Optimize _.pluck for modern environments.
Former-commit-id: 1a6bbb9866b8ac20faaa707be5f33814579e1df8
This commit is contained in:
16
build.js
16
build.js
@@ -1895,6 +1895,22 @@
|
||||
'}'
|
||||
].join('\n'));
|
||||
|
||||
// replace `_.pluck`
|
||||
source = replaceFunction(source, 'pluck', [
|
||||
'function pluck(collection, property) {',
|
||||
' var index = -1,',
|
||||
' length = collection ? collection.length : 0;',
|
||||
'',
|
||||
" if (typeof length == 'number') {",
|
||||
' var result = Array(length);',
|
||||
' while (++index < length) {',
|
||||
' result[index] = collection[index][property]',
|
||||
' }',
|
||||
' }',
|
||||
' return result || map(collection, property);',
|
||||
'}'
|
||||
].join('\n'));
|
||||
|
||||
// replace `isArray(collection)` checks in "Collections" methods with simpler type checks
|
||||
_.each(['every', 'filter', 'find', 'max', 'min', 'reduce', 'some'], function(methodName) {
|
||||
source = source.replace(matchFunction(source, methodName), function(match) {
|
||||
|
||||
Reference in New Issue
Block a user