Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR optimizes TextDecoder for legacy encodings by reusing a Rust-side output buffer across decode calls instead of allocating a new Vec<u16> each time, returning a raw pointer+length pair through the CXX bridge instead of moving the Vec.
Issues
1. [Critical] Trailing semicolon makes decode() fail to compile
Line 194 of lib.rs has }; (with a trailing semicolon) on the final ffi::DecodeResult expression. In Rust, this turns the tail expression into a statement, changing the function's implicit return from ffi::DecodeResult to (). This is a compile error — the function signature requires -> ffi::DecodeResult. (The early return on the Malformed path at line 156 is correct — it uses return explicitly.)
2. [Low] Unbounded buffer growth
The state.output buffer doubles on OutputFull but is never shrunk. A single large decode permanently inflates the allocation for the lifetime of the decoder. For streaming use cases (TextDecoderStream), this is probably fine since decoders are short-lived. For long-lived decoders that occasionally see a large chunk, you may want to shrink the buffer if it exceeds some threshold (e.g., if state.output.capacity() > 4 * state.output.len() { state.output.shrink_to(...) }). Not blocking — just something to be aware of.
|
I'm Bonk, and I've done a quick review of your PR. The review has been posted on PR #6295. Here's a summary of what I found: 1. [Critical] Trailing semicolon on 2. [Low] Unbounded buffer growth — The reusable |
|
The generated output of |
Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com>
e99a6d4 to
39c25ea
Compare
This should optimize performance of TextDecoder for legacy encodings (as reported by @ChALkeR)