Skip to content

Commit

Permalink
Merge branch '2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 12, 2023
2 parents e1bbcaa + 0ff5f9f commit 412acae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Objects;

import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.EncoderFactory;

import tools.jackson.core.*;
import tools.jackson.core.base.GeneratorBase;
Expand Down Expand Up @@ -98,6 +99,11 @@ private Feature(boolean defaultState) {
/**********************************************************************
*/

/**
* @since 2.16
*/
protected final static EncoderFactory ENCODER_FACTORY = EncoderFactory.get();

/**
* Bit flag composed of bits that indicate which
* {@link AvroGenerator.Feature}s
Expand Down Expand Up @@ -152,7 +158,11 @@ public AvroGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt,
_formatWriteFeatures = avroFeatures;
_output = output;
_streamWriteContext = AvroWriteContext.nullContext();
_encoder = ApacheCodecRecycler.encoder(_output, isEnabled(Feature.AVRO_BUFFERING));
final boolean buffering = isEnabled(Feature.AVRO_BUFFERING);
BinaryEncoder encoderToReuse = ApacheCodecRecycler.acquireEncoder();
_encoder = buffering
? ENCODER_FACTORY.binaryEncoder(output, encoderToReuse)
: ENCODER_FACTORY.directBinaryEncoder(output, encoderToReuse);
_rootSchema = Objects.requireNonNull(schema, "Can not pass `null` 'schema'");
// start with temporary root...
_streamWriteContext = _rootContext = AvroWriteContext.createRootContext(this,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tools.jackson.dataformat.avro.apacheimpl;

import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.SoftReference;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -17,8 +16,6 @@ public final class ApacheCodecRecycler
{
protected final static DecoderFactory DECODER_FACTORY = DecoderFactory.get();

protected final static EncoderFactory ENCODER_FACTORY = EncoderFactory.get();

protected final static ThreadLocal<SoftReference<ApacheCodecRecycler>> _recycler
= new ThreadLocal<SoftReference<ApacheCodecRecycler>>();

Expand Down Expand Up @@ -47,12 +44,8 @@ public static BinaryDecoder decoder(byte[] buffer, int offset, int len)
return DECODER_FACTORY.binaryDecoder(buffer, offset, len, prev);
}

public static BinaryEncoder encoder(OutputStream out, boolean buffering)
{
BinaryEncoder prev = _recycler().claimEncoder();
return buffering
? ENCODER_FACTORY.binaryEncoder(out, prev)
: ENCODER_FACTORY.directBinaryEncoder(out, prev);
public static BinaryEncoder acquireEncoder() {
return _recycler().claimEncoder();
}

public static void release(BinaryDecoder dec) {
Expand Down

0 comments on commit 412acae

Please sign in to comment.