From 1045f287b82e4353e6855878fa48ab3fde86c7e1 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; }