-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[useId] Trade random collisions for collisions on overflow (#29781)
- Loading branch information
Showing
1 changed file
with
5 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Although
9007199254740992
is a pretty large number, if you want to avoid collisions on overflow (and in JavaScript it's pretty bad, tryMath.pow(2,53) + 1
, useglobalId = 0n
and++globalId
. You could also tryglobalId = 0
andglobalId = globalId + 1 | 0
but that would overflow afterMath.pow(2,31) - 1
and send you to negative numbers.