Skip to content

Commit

Permalink
Replace double tilde with Math.floor (#30691)
Browse files Browse the repository at this point in the history
Nowadays, browser engines have improved a lot and `Math.floor` is the same, if not faster.
Also, clarity is better than micro-optimizations in this case.
  • Loading branch information
XhmikosR committed May 14, 2020
1 parent ddf39a5 commit 7966167
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion js/src/util/index.js
Expand Up @@ -26,7 +26,7 @@ const toType = obj => {

const getUID = prefix => {
do {
prefix += ~~(Math.random() * MAX_UID) // "~~" acts like a faster Math.floor() here
prefix += Math.floor(Math.random() * MAX_UID)
} while (document.getElementById(prefix))

return prefix
Expand Down

0 comments on commit 7966167

Please sign in to comment.