mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Optimize _.union.
Former-commit-id: 0cba8cac81a621b1fdbe8868ab406a30eb1d743f
This commit is contained in:
@@ -3140,11 +3140,13 @@
|
||||
if (isLarge) {
|
||||
// manually coerce `computed` to a string because `hasOwnProperty`, in
|
||||
// some older versions of Firefox, coerces objects incorrectly
|
||||
seen = hasOwnProperty.call(cache, computed + '') ? cache[computed] : (cache[computed] = []);
|
||||
var inited = hasOwnProperty.call(cache, computed + '')
|
||||
? !(seen = cache[computed])
|
||||
: (seen = []);
|
||||
}
|
||||
if (isSorted
|
||||
? !index || seen[seen.length - 1] !== computed
|
||||
: indexOf(seen, computed) < 0
|
||||
: inited || indexOf(seen, computed) < 0
|
||||
) {
|
||||
if (callback || isLarge) {
|
||||
seen.push(computed);
|
||||
|
||||
36
perf/perf.js
36
perf/perf.js
@@ -1631,6 +1631,42 @@
|
||||
)
|
||||
);
|
||||
|
||||
suites.push(
|
||||
Benchmark.Suite('`_.union` iterating an array of 50 elements')
|
||||
.add(buildName, {
|
||||
'fn': 'lodash.union(twentyFiveValues, twentyFiveValues2);',
|
||||
'teardown': 'function multiArrays(){}'
|
||||
})
|
||||
.add(otherName, {
|
||||
'fn': '_.union(twentyFiveValues, twentyFiveValues2);',
|
||||
'teardown': 'function multiArrays(){}'
|
||||
})
|
||||
);
|
||||
|
||||
suites.push(
|
||||
Benchmark.Suite('`_.union` iterating an array of 75 elements')
|
||||
.add(buildName, {
|
||||
'fn': 'lodash.union(fiftyValues, twentyFiveValues2);',
|
||||
'teardown': 'function multiArrays(){}'
|
||||
})
|
||||
.add(otherName, {
|
||||
'fn': '_.union(fiftyValues, twentyFiveValues2);',
|
||||
'teardown': 'function multiArrays(){}'
|
||||
})
|
||||
);
|
||||
|
||||
suites.push(
|
||||
Benchmark.Suite('`_.union` iterating an array of 100 elements')
|
||||
.add(buildName, {
|
||||
'fn': 'lodash.union(seventyFiveValues, twentyFiveValues2);',
|
||||
'teardown': 'function multiArrays(){}'
|
||||
})
|
||||
.add(otherName, {
|
||||
'fn': '_.union(seventyFiveValues, twentyFiveValues2);',
|
||||
'teardown': 'function multiArrays(){}'
|
||||
})
|
||||
);
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
suites.push(
|
||||
|
||||
Reference in New Issue
Block a user