Skip to content

Commit aeb9363

Browse files
authored
fix: Performance improvement by reducing calls to toString() (#4092)
performance improvement by reducing calls to toString()
1 parent da305b2 commit aeb9363

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/_internal/utils/hash.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { OBJECT, isUndefined } from './shared'
66
// complexity is almost O(1).
77
const table = new WeakMap<object, number | string>()
88

9-
const isObjectType = (value: any, type: string) =>
10-
OBJECT.prototype.toString.call(value) === `[object ${type}]`
9+
const getTypeName = (value: any) => OBJECT.prototype.toString.call(value)
10+
11+
const isObjectTypeName = (typeName: string, type: string) =>
12+
typeName === `[object ${type}]`
1113

1214
// counter of the key
1315
let counter = 0
@@ -22,9 +24,10 @@ let counter = 0
2224
// parsable.
2325
export const stableHash = (arg: any): string => {
2426
const type = typeof arg
25-
const isDate = isObjectType(arg, 'Date')
26-
const isRegex = isObjectType(arg, 'RegExp')
27-
const isPlainObject = isObjectType(arg, 'Object')
27+
const typeName = getTypeName(arg)
28+
const isDate = isObjectTypeName(typeName, 'Date')
29+
const isRegex = isObjectTypeName(typeName, 'RegExp')
30+
const isPlainObject = isObjectTypeName(typeName, 'Object')
2831
let result: any
2932
let index: any
3033

0 commit comments

Comments
 (0)