Hello,
I want to take advantage of StringBuilder plumbing in the core module.
There are two Encoder<StringBuilder> implementations:
StringBuilderEncoder and LockingStringBuilderEncoder. Given
JsonTemplateLayout has its own customizable recycling strategy, I
can't use StringBuilderEncoder due to its TLAs.
LockingStringBuilderEncoder, even though I cannot find any usage of
this class, contains the following interesting bit:
// This synchronized is needed to be able to call destination.getByteBuffer()
synchronized (destination) {
TextEncoderHelper.encodeText(charsetEncoder, cachedCharBuffer,
destination.getByteBuffer(), source,
destination);
}
Why doesn't there exist a ByteBuffer class field but rather it relies
on destination.getByteBuffer()? This would have eliminated the need
for the synchronized block. For instance, StringBuilderEncoder has its
own thread-local ByteBuffer and avoids the synchronized.
Kinds regards.