diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2022-10-20 07:07:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-20 09:37:37 +0530 |
commit | e2be70b035459cb534360b72ece4ff2abaa09cd7 (patch) | |
tree | 6be089ecce80843c01cd85cd2ff049d03f9e0955 /ext/ffi/00_ffi.js | |
parent | 722ea20e860df0a568b5d97734ad8d89aa7382a9 (diff) |
feat(ext/ffi): Make op_ffi_ptr_of fast (#16297)
Makes `op_ffi_ptr_of` fast. One of the tests changed from printing
`false` to `true` as the fast `&[u8]` slice path creates the slice with
a null pointer. Thus the `op_ffi_ptr_of` will now return a null pointer
value whereas previously it returned a dangling pointer value.
Diffstat (limited to 'ext/ffi/00_ffi.js')
-rw-r--r-- | ext/ffi/00_ffi.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index f5b0fb4c3..1b340a766 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -160,12 +160,19 @@ } } + const OUT_BUFFER = new Uint32Array(2); + const OUT_BUFFER_64 = new BigInt64Array(OUT_BUFFER.buffer); class UnsafePointer { static of(value) { if (ObjectPrototypeIsPrototypeOf(UnsafeCallbackPrototype, value)) { return value.pointer; } - return ops.op_ffi_ptr_of(value); + ops.op_ffi_ptr_of(value, OUT_BUFFER); + const result = OUT_BUFFER[0] + 2 ** 32 * OUT_BUFFER[1]; + if (NumberIsSafeInteger(result)) { + return result; + } + return OUT_BUFFER_64[0]; } } |