Commit b471f26b715 for nodejs
commit b471f26b715f3a4f5c6c2542e13a2cb61362a225
Author: Roberto Bianchi <roberto.bianchi@spendesk.com>
Date: Fri Dec 4 00:47:57 2026 +0100
ffi: avoid mutable push on private arrays
The shared-buffer and fast API wrappers collected per-argument type
info, offsets and indexes with .push() on private arrays, which looks
up Array.prototype.push at call time. Replacing that method from user
code changed how wrapped functions were built. Use indexed assignments
instead.
Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
PR-URL: https://github.com/nodejs/node/pull/67895
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
diff --git a/lib/internal/ffi-shared-buffer.js b/lib/internal/ffi-shared-buffer.js
index 68b39ab62f9..3156ca2f733 100644
--- a/lib/internal/ffi-shared-buffer.js
+++ b/lib/internal/ffi-shared-buffer.js
@@ -259,8 +259,8 @@ function wrapWithSharedBuffer(rawFn, signature) {
// share a shape, keeping `writeNumericArg`'s call sites
// low-polymorphism) and store offsets in a parallel array to avoid
// per-arg object cloning.
- argInfos.push(info);
- argOffsets.push(8 * (i + 1));
+ argInfos[argInfos.length] = info;
+ argOffsets[argOffsets.length] = 8 * (i + 1);
if (info.kind === 'pointer') anyPointer = true;
}
diff --git a/lib/internal/ffi/fast-api.js b/lib/internal/ffi/fast-api.js
index 531d4d41005..a86c2c31241 100644
--- a/lib/internal/ffi/fast-api.js
+++ b/lib/internal/ffi/fast-api.js
@@ -230,7 +230,7 @@ function getFastArgumentIndexes(argumentsTypes) {
if (indexes === null) {
indexes = [];
}
- indexes.push(i);
+ indexes[indexes.length] = i;
}
return indexes;
}