From db1238aae3de5b6d7da62598a2f4f0c1dca2d3fa Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 29 Oct 2024 16:35:44 +0100 Subject: [PATCH] Re-factor the `toHexUtil` helper (PR 17862 follow-up) We can re-use the `hexNumbers` structure, since that allows us to directly lookup the hexadecimal values and shortens the code. --- src/shared/util.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/shared/util.js b/src/shared/util.js index 700f9f871..b61a58abc 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -1102,11 +1102,7 @@ function toHexUtil(arr) { if (Uint8Array.prototype.toHex) { return arr.toHex(); } - const buf = []; - for (const num of arr) { - buf.push(num.toString(16).padStart(2, "0")); - } - return buf.join(""); + return Array.from(arr, num => hexNumbers[num]).join(""); } // TODO: Remove this once `Uint8Array.prototype.toBase64` is generally