Skip to content

Commit 1038199

Browse files
committed
Update preexisting-issues.md to reflect writeString(Reader, int) fix
1 parent 97e0751 commit 1038199

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

plans/preexisting-issues.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ regression by defeating the ThreadLocal caching (each close allocates a new
6161
accepting the minor OutputStream retention, which is only observable when a thread
6262
creates exactly one generator and never creates another.
6363

64-
### 5. `writeString(Reader, int)` len=-1 implementation allocates an extra copy
64+
### 5. `writeString(Reader, int)` len≥0 path allocates unbounded buffer — FIXED
6565

6666
**File:** `msgpack-jackson3/.../MessagePackGenerator.java` (writeString(Reader, int))
6767

68-
The len=-1 path buffers into a `StringBuilder` then copies to a `char[]`. Using a
69-
`CharArrayWriter` would avoid the intermediate allocation.
68+
The len≥0 path allocated `new char[len]` upfront — an unbounded allocation if the
69+
caller passed a large hint value. Fixed by switching to chunked reading (8192-char
70+
buffer) into a `StringBuilder`, matching the pattern already used in the len<0 branch.
71+
72+
The len<0 path (StringBuilder + 1024-char chunk) still allocates an extra copy vs.
73+
`CharArrayWriter`, but the overhead is minor and not worth optimizing at this layer.
7074

7175
---
7276

0 commit comments

Comments
 (0)