From cd891b37f654f0f0eb9850c63255b6698d820e98 Mon Sep 17 00:00:00 2001 From: Liu Jia <109258120+Septa2112@users.noreply.github.com> Date: Sun, 10 Dec 2023 16:41:25 +0800 Subject: [PATCH] util: improve performance of function areSimilarFloatArrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve performance of areSimilarFloatArrays by using primordial. Refs: https://github.com/nodejs/node/pull/50621 PR-URL: https://github.com/nodejs/node/pull/51040 Reviewed-By: Ruben Bridgewater Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: James M Snell --- lib/internal/util/comparisons.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/comparisons.js b/lib/internal/util/comparisons.js index d86e59adae9880..d26d887636c565 100644 --- a/lib/internal/util/comparisons.js +++ b/lib/internal/util/comparisons.js @@ -21,6 +21,7 @@ const { StringPrototypeValueOf, SymbolPrototypeValueOf, TypedArrayPrototypeGetSymbolToStringTag, + TypedArrayPrototypeGetByteLength, Uint8Array, } = primordials; @@ -71,7 +72,8 @@ function areSimilarFloatArrays(a, b) { if (a.byteLength !== b.byteLength) { return false; } - for (let offset = 0; offset < a.byteLength; offset++) { + const len = TypedArrayPrototypeGetByteLength(a); + for (let offset = 0; offset < len; offset++) { if (a[offset] !== b[offset]) { return false; }