Skip to content

Commit cba1ec2

Browse files
avoid string concatenation in message id generation
1 parent 128a78e commit cba1ec2

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/message-utils/src/generateMessageId.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ export function generateMessageId(msg: string, context = "") {
77
}
88

99
function hexToBase64(hexStr: string) {
10-
let base64 = ""
10+
const base64: string[] = []
11+
1112
for (let i = 0; i < hexStr.length; i++) {
12-
base64 += !((i - 1) & 1)
13-
? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16))
14-
: ""
13+
base64.push(
14+
!((i - 1) & 1)
15+
? String.fromCharCode(parseInt(hexStr.substring(i - 1, i + 1), 16))
16+
: ""
17+
)
1518
}
16-
return btoa(base64)
19+
20+
return btoa(base64.join(""))
1721
}

0 commit comments

Comments
 (0)