]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Replace double tilde with `Math.floor` (#30691)
authorXhmikosR <xhmikosr@gmail.com>
Thu, 14 May 2020 06:46:42 +0000 (09:46 +0300)
committerGitHub <noreply@github.com>
Thu, 14 May 2020 06:46:42 +0000 (09:46 +0300)
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.

js/src/util/index.js

index cee403481195a1c20823b6cf9a21a597a916c763..f92c7eb5d749f3bf1693d733ac0d280ab5de383a 100644 (file)
@@ -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