Skip to content

Commit

Permalink
fix: JsArrayBuffer usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed May 26, 2021
1 parent 9c2b16a commit b58e987
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ fn image_data_constructor(ctx: CallContext) -> Result<JsUndefined> {
.to_owned(),
));
}
let arraybuffer_length = image_data_ab.len();
let arraybuffer: &[u8] = image_data_ab.as_ref();
let arraybuffer_length = arraybuffer.len();
let js_width = ctx.get::<JsNumber>(1)?;
let width = js_width.get_uint32()?;
let (js_height, height) = if ctx.length == 3 {
Expand All @@ -75,8 +76,7 @@ fn image_data_constructor(ctx: CallContext) -> Result<JsUndefined> {
(js_height, height),
arraybuffer_length,
ManuallyDrop::new(unsafe {
slice::from_raw_parts(image_data_ab.as_ptr() as *const u8, arraybuffer_length)
.to_owned()
slice::from_raw_parts(arraybuffer.as_ptr() as *const u8, arraybuffer_length).to_owned()
}),
))
}
Expand Down

1 comment on commit b58e987

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: b58e987 Previous: 53de756 Ratio
Draw house#@napi-rs/skia 21 ops/sec (±1%) 26 ops/sec (±0.23%) 1.24
Draw house#node-canvas 18 ops/sec (±0.35%) 21 ops/sec (±0.32%) 1.17
Draw gradient#@napi-rs/skia 21 ops/sec (±0.19%) 25 ops/sec (±0.08%) 1.19
Draw gradient#node-canvas 17 ops/sec (±0.25%) 20 ops/sec (±0.25%) 1.18

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.