Skip to content

Commit

Permalink
perfomance fixes, eslint fixes (lodash#4482)
Browse files Browse the repository at this point in the history
  • Loading branch information
anatoliik-lyft authored and jdalton committed Sep 26, 2019
1 parent 29eb571 commit 898b378
Show file tree
Hide file tree
Showing 73 changed files with 89 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .internal/MapCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Hash from './Hash.js'
function getMapData({ __data__ }, key) {
const data = __data__
return isKeyable(key)
? data[typeof key == 'string' ? 'string' : 'hash']
? data[typeof key === 'string' ? 'string' : 'hash']
: data.map
}

Expand All @@ -25,7 +25,7 @@ function getMapData({ __data__ }, key) {
*/
function isKeyable(value) {
const type = typeof value
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
return (type === 'string' || type === 'number' || type === 'symbol' || type === 'boolean')
? (value !== '__proto__')
: (value === null)
}
Expand Down
2 changes: 1 addition & 1 deletion .internal/arrayLikeKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function arrayLikeKeys(value, inherited) {
if ((inherited || hasOwnProperty.call(value, key)) &&
!(skipIndexes && (
// Safari 9 has enumerable `arguments.length` in strict mode.
(key == 'length' ||
(key === 'length' ||
// Skip index properties.
isIndex(key, length))
))) {
Expand Down
2 changes: 1 addition & 1 deletion .internal/assignValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function assignValue(object, key, value) {
const objValue = object[key]

if (!(hasOwnProperty.call(object, key) && eq(objValue, value))) {
if (value !== 0 || (1 / value) == (1 / objValue)) {
if (value !== 0 || (1 / value) === (1 / objValue)) {
baseAssignValue(object, key, value)
}
} else if (value === undefined && !(key in object)) {
Expand Down
4 changes: 2 additions & 2 deletions .internal/baseClone.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function initCloneArray(array) {
const result = new array.constructor(length)

// Add properties assigned by `RegExp#exec`.
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
if (length && typeof array[0] === 'string' && hasOwnProperty.call(array, 'index')) {
result.index = array.index
result.input = array.input
}
Expand Down Expand Up @@ -177,7 +177,7 @@ function baseClone(value, bitmask, customizer, key, object, stack) {
return copyArray(value, result)
}
} else {
const isFunc = typeof value == 'function'
const isFunc = typeof value === 'function'

if (isBuffer(value)) {
return cloneBuffer(value, isDeep)
Expand Down
2 changes: 1 addition & 1 deletion .internal/baseMatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import matchesStrictComparable from './matchesStrictComparable.js'
*/
function baseMatches(source) {
const matchData = getMatchData(source)
if (matchData.length == 1 && matchData[0][2]) {
if (matchData.length === 1 && matchData[0][2]) {
return matchesStrictComparable(matchData[0][0], matchData[0][1])
}
return (object) => object === source || baseIsMatch(object, source, matchData)
Expand Down
2 changes: 1 addition & 1 deletion .internal/baseMergeDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta
if (isArguments(objValue)) {
newValue = toPlainObject(objValue)
}
else if (typeof objValue == 'function' || !isObject(objValue)) {
else if (typeof objValue === 'function' || !isObject(objValue)) {
newValue = initCloneObject(srcValue)
}
}
Expand Down
2 changes: 1 addition & 1 deletion .internal/basePullAt.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function basePullAt(array, indexes) {
while (length--) {
let previous
const index = indexes[length]
if (length == lastIndex || index !== previous) {
if (length === lastIndex || index !== previous) {
previous = index
if (isIndex(index)) {
array.splice(index, 1)
Expand Down
2 changes: 1 addition & 1 deletion .internal/baseSortedIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function baseSortedIndex(array, value, retHighest) {
let low = 0
let high = array == null ? low : array.length

if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
if (typeof value === 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
while (low < high) {
const mid = (low + high) >>> 1
const computed = array[mid]
Expand Down
2 changes: 1 addition & 1 deletion .internal/baseToNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const NAN = 0 / 0
* @returns {number} Returns the number.
*/
function baseToNumber(value) {
if (typeof value == 'number') {
if (typeof value === 'number') {
return value
}
if (isSymbol(value)) {
Expand Down
2 changes: 1 addition & 1 deletion .internal/baseToString.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const symbolToString = Symbol.prototype.toString
*/
function baseToString(value) {
// Exit early for strings to avoid a performance hit in some environments.
if (typeof value == 'string') {
if (typeof value === 'string') {
return value
}
if (Array.isArray(value)) {
Expand Down
4 changes: 2 additions & 2 deletions .internal/cloneBuffer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import root from './root.js'

/** Detect free variable `exports`. */
const freeExports = typeof exports == 'object' && exports !== null && !exports.nodeType && exports
const freeExports = typeof exports === 'object' && exports !== null && !exports.nodeType && exports

/** Detect free variable `module`. */
const freeModule = freeExports && typeof module == 'object' && module !== null && !module.nodeType && module
const freeModule = freeExports && typeof module === 'object' && module !== null && !module.nodeType && module

/** Detect the popular CommonJS extension `module.exports`. */
const moduleExports = freeModule && freeModule.exports === freeExports
Expand Down
2 changes: 1 addition & 1 deletion .internal/compareAscending.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function compareAscending(value, other) {
const othIsReflexive = other === other
const othIsSymbol = isSymbol(other)

const val = typeof value == 'string'
const val = typeof value === 'string'
? value.localeCompare(other)
: -other

Expand Down
2 changes: 1 addition & 1 deletion .internal/createAssigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function createAssigner(assigner) {
let customizer = length > 1 ? sources[length - 1] : undefined
const guard = length > 2 ? sources[2] : undefined

customizer = (assigner.length > 3 && typeof customizer == 'function')
customizer = (assigner.length > 3 && typeof customizer === 'function')
? (length--, customizer)
: undefined

Expand Down
4 changes: 2 additions & 2 deletions .internal/equalObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
// Non `Object` object instances with different constructors are not equal.
if (objCtor != othCtor &&
('constructor' in object && 'constructor' in other) &&
!(typeof objCtor == 'function' && objCtor instanceof objCtor &&
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
!(typeof objCtor === 'function' && objCtor instanceof objCtor &&
typeof othCtor === 'function' && othCtor instanceof othCtor)) {
result = false
}
}
Expand Down
2 changes: 1 addition & 1 deletion .internal/freeGlobal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Detect free variable `global` from Node.js. */
const freeGlobal = typeof global == 'object' && global !== null && global.Object === Object && global
const freeGlobal = typeof global === 'object' && global !== null && global.Object === Object && global

export default freeGlobal
2 changes: 1 addition & 1 deletion .internal/initCloneObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import isPrototype from './isPrototype.js'
* @returns {Object} Returns the initialized clone.
*/
function initCloneObject(object) {
return (typeof object.constructor == 'function' && !isPrototype(object))
return (typeof object.constructor === 'function' && !isPrototype(object))
? Object.create(Object.getPrototypeOf(object))
: {}
}
Expand Down
4 changes: 2 additions & 2 deletions .internal/isIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ function isIndex(value, length) {
length = length == null ? MAX_SAFE_INTEGER : length

return !!length &&
(type == 'number' ||
(type != 'symbol' && reIsUint.test(value))) &&
(type === 'number' ||
(type !== 'symbol' && reIsUint.test(value))) &&
(value > -1 && value % 1 == 0 && value < length)
}

Expand Down
4 changes: 2 additions & 2 deletions .internal/isIterateeCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ function isIterateeCall(value, index, object) {
return false
}
const type = typeof index
if (type == 'number'
if (type === 'number'
? (isArrayLike(object) && isIndex(index, object.length))
: (type == 'string' && index in object)
: (type === 'string' && index in object)
) {
return eq(object[index], value)
}
Expand Down
2 changes: 1 addition & 1 deletion .internal/isKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function isKey(value, object) {
return false
}
const type = typeof value
if (type == 'number' || type == 'boolean' || value == null || isSymbol(value)) {
if (type === 'number' || type === 'boolean' || value == null || isSymbol(value)) {
return true
}
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
Expand Down
2 changes: 1 addition & 1 deletion .internal/isPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const objectProto = Object.prototype
*/
function isPrototype(value) {
const Ctor = value && value.constructor
const proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto
const proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto

return value === proto
}
Expand Down
4 changes: 2 additions & 2 deletions .internal/nodeTypes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import freeGlobal from './freeGlobal.js'

/** Detect free variable `exports`. */
const freeExports = typeof exports == 'object' && exports !== null && !exports.nodeType && exports
const freeExports = typeof exports === 'object' && exports !== null && !exports.nodeType && exports

/** Detect free variable `module`. */
const freeModule = freeExports && typeof module == 'object' && module !== null && !module.nodeType && module
const freeModule = freeExports && typeof module === 'object' && module !== null && !module.nodeType && module

/** Detect the popular CommonJS extension `module.exports`. */
const moduleExports = freeModule && freeModule.exports === freeExports
Expand Down
4 changes: 2 additions & 2 deletions .internal/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import freeGlobal from './freeGlobal.js'

/** Detect free variable `globalThis` */
const freeGlobalThis = typeof globalThis == 'object' && globalThis !== null && globalThis.Object == Object && globalThis
const freeGlobalThis = typeof globalThis === 'object' && globalThis !== null && globalThis.Object == Object && globalThis

/** Detect free variable `self`. */
const freeSelf = typeof self == 'object' && self !== null && self.Object === Object && self
const freeSelf = typeof self === 'object' && self !== null && self.Object === Object && self

/** Used as a reference to the global object. */
const root = freeGlobalThis || freeGlobal || freeSelf || Function('return this')()
Expand Down
2 changes: 1 addition & 1 deletion .internal/toKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const INFINITY = 1 / 0
* @returns {string|symbol} Returns the key.
*/
function toKey(value) {
if (typeof value == 'string' || isSymbol(value)) {
if (typeof value === 'string' || isSymbol(value)) {
return value
}
const result = `${value}`
Expand Down
2 changes: 1 addition & 1 deletion after.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* // => Logs 'done saving!' after the two async saves have completed.
*/
function after(n, func) {
if (typeof func != 'function') {
if (typeof func !== 'function') {
throw new TypeError('Expected a function')
}
n = n || 0
Expand Down
2 changes: 1 addition & 1 deletion before.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
function before(n, func) {
let result
if (typeof func != 'function') {
if (typeof func !== 'function') {
throw new TypeError('Expected a function')
}
return function(...args) {
Expand Down
2 changes: 1 addition & 1 deletion cloneDeepWith.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const CLONE_SYMBOLS_FLAG = 4
* // => 20
*/
function cloneDeepWith(value, customizer) {
customizer = typeof customizer == 'function' ? customizer : undefined
customizer = typeof customizer === 'function' ? customizer : undefined
return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer)
}

Expand Down
2 changes: 1 addition & 1 deletion cloneWith.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const CLONE_SYMBOLS_FLAG = 4
* // => 0
*/
function cloneWith(value, customizer) {
customizer = typeof customizer == 'function' ? customizer : undefined
customizer = typeof customizer === 'function' ? customizer : undefined
return baseClone(value, CLONE_SYMBOLS_FLAG, customizer)
}

Expand Down
2 changes: 1 addition & 1 deletion cond.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function cond(pairs) {
const length = pairs == null ? 0 : pairs.length

pairs = !length ? [] : map(pairs, (pair) => {
if (typeof pair[1] != 'function') {
if (typeof pair[1] !== 'function') {
throw new TypeError('Expected a function')
}
return [pair[0], pair[1]]
Expand Down
2 changes: 1 addition & 1 deletion defer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* // => Logs 'deferred' after one millisecond.
*/
function defer(func, ...args) {
if (typeof func != 'function') {
if (typeof func !== 'function') {
throw new TypeError('Expected a function')
}
return setTimeout(func, 1, ...args)
Expand Down
2 changes: 1 addition & 1 deletion delay.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* // => Logs 'later' after one second.
*/
function delay(func, wait, ...args) {
if (typeof func != 'function') {
if (typeof func !== 'function') {
throw new TypeError('Expected a function')
}
return setTimeout(func, +wait || 0, ...args)
Expand Down
2 changes: 1 addition & 1 deletion flip.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* // => ['d', 'c', 'b', 'a']
*/
function flip(func) {
if (typeof func != 'function') {
if (typeof func !== 'function') {
throw new TypeError('Expected a function')
}
return function(...args) {
Expand Down
4 changes: 2 additions & 2 deletions flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @example
*
* import add from 'lodash/add'
*
*
* function square(n) {
* return n * n
* }
Expand All @@ -24,7 +24,7 @@ function flow(...funcs) {
const length = funcs ? funcs.length : 0
let index = length
while (index--) {
if (typeof funcs[index] != 'function') {
if (typeof funcs[index] !== 'function') {
throw new TypeError('Expected a function')
}
}
Expand Down
2 changes: 1 addition & 1 deletion flowRight.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import flow from './flow.js'
* @example
*
* import add from 'lodash/add'
*
*
* function square(n) {
* return n * n
* }
Expand Down
2 changes: 1 addition & 1 deletion functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function functions(object) {
if (object == null) {
return []
}
return Object.keys(object).filter((key) => typeof object[key] == 'function')
return Object.keys(object).filter((key) => typeof object[key] === 'function')
}

export default functions
2 changes: 1 addition & 1 deletion gt.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* // => false
*/
function gt(value, other) {
if (!(typeof value == 'string' && typeof other == 'string')) {
if (!(typeof value === 'string' && typeof other === 'string')) {
value = +value
other = +other
}
Expand Down
2 changes: 1 addition & 1 deletion gte.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* // => false
*/
function gte(value, other) {
if (!(typeof value == 'string' && typeof other == 'string')) {
if (!(typeof value === 'string' && typeof other === 'string')) {
value = +value
other = +other
}
Expand Down
2 changes: 1 addition & 1 deletion intersectionWith.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function intersectionWith(...arrays) {
let comparator = last(arrays)
const mapped = map(arrays, castArrayLikeObject)

comparator = typeof comparator == 'function' ? comparator : undefined
comparator = typeof comparator === 'function' ? comparator : undefined
if (comparator) {
mapped.pop()
}
Expand Down
2 changes: 1 addition & 1 deletion invert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function invert(object) {
const result = {}
Object.keys(object).forEach((key) => {
let value = object[key]
if (value != null && typeof value.toString != 'function') {
if (value != null && typeof value.toString !== 'function') {
value = toString.call(value)
}
result[value] = key
Expand Down
2 changes: 1 addition & 1 deletion invokeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import isArrayLike from './isArrayLike.js'
*/
function invokeMap(collection, path, args) {
let index = -1
const isFunc = typeof path == 'function'
const isFunc = typeof path === 'function'
const result = isArrayLike(collection) ? new Array(collection.length) : []

baseEach(collection, (value) => {
Expand Down
Loading

0 comments on commit 898b378

Please sign in to comment.