Skip to content

Commit 7720742

Browse files
authored
Do not calculate expression twice in Node.js where size is not important (#580)
1 parent f3cb594 commit 7720742

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ export function customRandom(alphabet, defaultSize, getRandom) {
5858
// A compact alternative for `for (let i = 0; i < step; i++)`.
5959
let i = step
6060
while (i--) {
61+
let next = alphabet[bytes[i] & mask]
6162
// Adding `continue` refuses a random byte that exceeds the alphabet size.
62-
if (!alphabet[bytes[i] & mask]) continue
63-
id += alphabet[bytes[i] & mask]
63+
if (!next) continue
64+
id += next
6465
if (id.length >= size) return id
6566
}
6667
}

0 commit comments

Comments
 (0)