createCache.js 650 B

123456789101112131415161718192021
  1. var SetCache = require('./SetCache'),
  2. getNative = require('./getNative');
  3. /** Native method references. */
  4. var Set = getNative(global, 'Set');
  5. /* Native method references for those with the same name as other `lodash` methods. */
  6. var nativeCreate = getNative(Object, 'create');
  7. /**
  8. * Creates a `Set` cache object to optimize linear searches of large arrays.
  9. *
  10. * @private
  11. * @param {Array} [values] The values to cache.
  12. * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
  13. */
  14. function createCache(values) {
  15. return (nativeCreate && Set) ? new SetCache(values) : null;
  16. }
  17. module.exports = createCache;