From 0e4896469e80def4d8931dad8779f34ec9514c2a Mon Sep 17 00:00:00 2001 From: Jia Liu Date: Mon, 4 Dec 2023 22:30:53 +0800 Subject: [PATCH] util: improve performance of function areSimilarFloatArrays Improve performance of areSimilarFloatArrays by using primordial. Refs: https://github.com/nodejs/node/pull/50621 --- 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; }