Repository navigation
refactor(napi): drop mem::forget round-trip in JsString::into_* - #3707
Conversation
|
Caution Review failedThe pull request is closed. No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
ba233dc to
f3138cd
Compare
mem::forget round trip in JsString::intomem::forget round-trip in JsString::into_*
`into_utf8` and `into_latin1` allocated a `Vec<c_char>`, then used `mem::forget` + `Vec::from_raw_parts` to turn it into a `Vec<u8>` shortened to what N-API wrote. Allocate a `Vec<u8>` up front instead, casting the pointer at the N-API call, so `truncate` does the same job without `unsafe` and the `Vec` can be moved into the result directly. Also drop the `buf_ptr` locals (including in `into_utf16`) and take pointers from the `Vec` where needed. No behaviour change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
f3138cd to
3a5d36e
Compare
Pure refactor - no behaviour change.
into_utf8andinto_latin1performed something of a dance - allocate aVec<c_char>, thenmem::forgetit, and create a newVecwithVec::from_raw_partsto turn it into aVec<u8>.Simplify this by allocating a
Vec<u8>up front, casting the pointer at the N-API call, sotruncatedoes the same job withoutunsafeand theVeccan be moved into the result directly.Also drop the
buf_ptrlocals (including ininto_utf16) and take pointers from theVecwhere needed.Based on top of #3706.
Summary by CodeRabbit