Repository navigation
perf(napi): JsStringUtf8 avoid memory copies in into_owned and take - #3711
Conversation
|
Caution Review failedThe pull request is closed. No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
03502b8 to
f8da669
Compare
…ake` Both take `self` by value, so move the buffer out instead of copying it. This saves an allocation and a copy of the whole string on every call, including when capturing error messages, which go through `into_utf8().into_owned()`. The returned `String` / `Vec<u8>` now has 1 byte of spare capacity, from the slot N-API wrote the NUL terminator into. Co-Authored-By: Claude Opus 5.5 <[email protected]>
f8da669 to
5e1dd9e
Compare
JsStringUtf8::into_ownedandJsStringUtf8::takeboth takeselfby value, so move the buffer out instead of copying it. This saves an allocation and a copy of the whole string on every call, including when capturing error messages, which go throughinto_utf8().into_owned().The returned
String/Vec<u8>now has 1 byte of spare capacity, from the slot N-API wrote the NUL terminator into.Based on top of #3710.
Summary by CodeRabbit
Bug Fixes
Tests