Repository navigation
refactor(napi): clarify naming and comments in string conversions - #3706
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
I've done this as a stack, as it's the process I'm used to and I find it helpful for review. I built the stack using Graphite locally, but couldn't submit using Graphite. PRs should merge cleanly on top of each other in this order:
@Brooooooklyn If this is a pain, please just say so and I'll squash it all to 1 PR. For review, you can see the whole stack as 6 x commits in #3711. I've deleted the CodeRabbit comments from the PR descriptions, as they were inaccurate - each one summarized the whole stack up to that commit, rather just the last commit that PR adds. |
72b87f9 to
1d0aaa6
Compare
|
Thanks for the stack. I rebased it onto current
Checked on each commit: clippy |
Pure refactor, no behaviour change. - Rename `written_char_count` (and `written` in `owned_string_without_coercion`) to `written_byte_count` (UTF-8, Latin-1) or `written_code_unit_count` (UTF-16), which is what N-API reports. - Rename the buffers to `bytes` (UTF-8, Latin-1) or `code_units` (UTF-16), instead of a mix of `ret`, `buf` and `result`. - Explain the `+ 1` for the NUL terminator. - Give every buffer an explicit element type (the type that was previously inferred), and drop a no-op pointer cast in `JsString::into_utf16`. - Add the missing SAFETY comment on `from_utf8_unchecked` in `String::from_napi_value`. - In `owned_string_without_coercion`, rename `length` to `len` and pass it as the buffer size instead of `bytes.len()` (the same value). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1d0aaa6 to
cc0089f
Compare
Pure refactor, no behaviour change.
Adopt consistent var naming and code layout in code which produces strings.
written_char_counttowritten_byte_count(UTF-8, Latin-1) orwritten_code_unit_count(UTF-16), which is what N-API reports.bytes(UTF-8, Latin-1) orcode_units(UTF-16) instead ofret/buf/result.+ 1for the NUL terminator.from_utf8_uncheckedinString::from_napi_value.owned_string_without_coercion, uselenconsistently and pass it as the buffer size instead ofbytes.len()(the same value).Also, remove a no-op pointer cast in
JsString::into_utf16.This just tidies things up in preparation for later PRs, so the substantive changes in those PRs have a clear diff.
Stack
mem::forgetround-trip inJsString::into_*#3707owned_string_without_coercionuse unchecked string conversion #3709JsStringUtf8contain aString#3710JsStringUtf8avoid memory copies ininto_ownedandtake#3711