1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

perf(serde_v8): avoid extra is_array_buffer_view check (#15056)

This commit is contained in:
Divy Srivastava 2022-07-04 07:00:42 +05:30 committed by GitHub
parent 9b5e6e64f2
commit 2c2126918b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,8 +70,7 @@ pub(crate) fn to_ranged_buffer<'s>(
scope: &mut v8::HandleScope<'s>,
value: v8::Local<v8::Value>,
) -> Result<(v8::Local<'s, v8::ArrayBuffer>, Range<usize>), v8::DataError> {
if value.is_array_buffer_view() {
let view: v8::Local<v8::ArrayBufferView> = value.try_into()?;
if let Ok(view) = v8::Local::<v8::ArrayBufferView>::try_from(value) {
let (offset, len) = (view.byte_offset(), view.byte_length());
let buffer = view.buffer(scope).ok_or(v8::DataError::NoData {
expected: "view to have a buffer",