File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,12 +61,16 @@ regression by defeating the ThreadLocal caching (each close allocates a new
6161accepting the minor OutputStream retention, which is only observable when a thread
6262creates 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
You can’t perform that action at this time.
0 commit comments