-
-
Notifications
You must be signed in to change notification settings - Fork 6
Conversation
38a01e3
to
29d7cc6
Compare
29d7cc6
to
6b9a8bb
Compare
|
||
hashed = nextHash(); | ||
|
||
symbolMap[sym] = hashed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is technically a memory leak. I'm just hoping there's no reason that programmers would create an unbounded number of symbols.
if (o == null) { | ||
return hashNullish(o); | ||
} | ||
|
||
if (typeof o.hashCode === 'function') { | ||
// Drop any high bits from accidentally long hash codes. | ||
return smi(o.hashCode(o)); | ||
} | ||
|
||
const v = valueOf(o); | ||
|
||
if (v == null) { | ||
return hashNullish(v); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we are moving this code of out of the 'object' || 'function'
case to the top of the method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite simply: require('moment')().valueOf()
, which returns a number (the timestamp). The current code assumes incorrectly that the result of object.valueOf()
is always an object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see now you're tackling immutable-js#1643 as well in this PR. I was trying to figure out what this code had to do with symbols, but now it makes sense.
Fixes an obvious bug:
TypeError: Cannot convert a Symbol value to a string
, and also tries to avoid the cost of hash collisions between symbols.This is an alternative to immutable-js#1753, based primarily on this comment.