On Mon, 17 Aug 2026 00:04:54 GMT, Chen Liang <[email protected]> wrote:

>> src/jdk.incubator.json/share/classes/jdk/incubator/json/JsonString.java line 
>> 69:
>> 
>>> 67:         return new JsonStringImpl(escaped.toCharArray(), 0, 
>>> escaped.length(),
>>> 68:                 escaped.length() != src.length() + 2);
>>> 69:     }
>> 
>> Would it make sense to optimize this, e.g. by having a `JsonStringImpl` 
>> constructor which takes the unescaped value?
>> 
>> Current behavior might not be ideal that `JsonString.of(...).asString()` can 
>> involve escaping and unescaping.
>> 
>> Edit: Maybe not relevant if you consider the two use cases 'parsing' 
>> (`Json#parse` + access) and 'generating' (`of(...)` + `toString`) separate, 
>> with little to no overlap. Then this would fall into the 'generating' 
>> category where the escaped string is needed anyway, and the unescaped one is 
>> not.
>
> `equals` would be much harder to implement correctly if we do not escape upon 
> construction.

Thanks. For this round of review, performance isn’t our primary focus. We can 
revisit it at a later stage

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/32282#discussion_r3797272299

Reply via email to