diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2022-10-20 07:05:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-20 09:35:56 +0530 |
commit | 722ea20e860df0a568b5d97734ad8d89aa7382a9 (patch) | |
tree | 7b5dea0f32318dcc8d7d98b0cc6d4a3384a5805c /ext/ffi/00_ffi.js | |
parent | 973069b341de65e8e32b91072ff5a745fe7e704a (diff) |
perf(ext/ffi): Fast UnsafePointerView read functions (#16351)
This PR makes pointer read methods of `Deno.UnsafePointerView` Fast API
compliant, with the exception of `getCString` which cannot be made fast
with current V8 Fast API.
Diffstat (limited to 'ext/ffi/00_ffi.js')
-rw-r--r-- | ext/ffi/00_ffi.js | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/ext/ffi/00_ffi.js b/ext/ffi/00_ffi.js index 3f5c57a9c..f5b0fb4c3 100644 --- a/ext/ffi/00_ffi.js +++ b/ext/ffi/00_ffi.js @@ -6,7 +6,6 @@ const ops = core.ops; const __bootstrap = window.__bootstrap; const { - BigInt, ObjectDefineProperty, ArrayPrototypeMap, Number, @@ -17,9 +16,13 @@ Int32Array, Uint32Array, BigInt64Array, + BigUint64Array, Function, } = window.__bootstrap.primordials; + const U32_BUFFER = new Uint32Array(2); + const U64_BUFFER = new BigUint64Array(U32_BUFFER.buffer); + const I64_BUFFER = new BigInt64Array(U32_BUFFER.buffer); class UnsafePointerView { pointer; @@ -29,99 +32,119 @@ getBool(offset = 0) { return ops.op_ffi_read_bool( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getUint8(offset = 0) { return ops.op_ffi_read_u8( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getInt8(offset = 0) { return ops.op_ffi_read_i8( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getUint16(offset = 0) { return ops.op_ffi_read_u16( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getInt16(offset = 0) { return ops.op_ffi_read_i16( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getUint32(offset = 0) { return ops.op_ffi_read_u32( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getInt32(offset = 0) { return ops.op_ffi_read_i32( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getBigUint64(offset = 0) { - return ops.op_ffi_read_u64( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + ops.op_ffi_read_u64( + this.pointer, + offset, + U32_BUFFER, ); + return U64_BUFFER[0]; } getBigInt64(offset = 0) { - return ops.op_ffi_read_i64( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + ops.op_ffi_read_i64( + this.pointer, + offset, + U32_BUFFER, ); + return I64_BUFFER[0]; } getFloat32(offset = 0) { return ops.op_ffi_read_f32( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getFloat64(offset = 0) { return ops.op_ffi_read_f64( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } getCString(offset = 0) { return ops.op_ffi_cstr_read( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, ); } static getCString(pointer, offset = 0) { return ops.op_ffi_cstr_read( - offset ? BigInt(pointer) + BigInt(offset) : pointer, + pointer, + offset, ); } getArrayBuffer(byteLength, offset = 0) { return ops.op_ffi_get_buf( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, byteLength, ); } static getArrayBuffer(pointer, byteLength, offset = 0) { return ops.op_ffi_get_buf( - offset ? BigInt(pointer) + BigInt(offset) : pointer, + pointer, + offset, byteLength, ); } copyInto(destination, offset = 0) { ops.op_ffi_buf_copy_into( - offset ? BigInt(this.pointer) + BigInt(offset) : this.pointer, + this.pointer, + offset, destination, destination.byteLength, ); @@ -129,7 +152,8 @@ static copyInto(pointer, destination, offset = 0) { ops.op_ffi_buf_copy_into( - offset ? BigInt(pointer) + BigInt(offset) : pointer, + pointer, + offset, destination, destination.byteLength, ); |