Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part 3 of changes for #393 #396

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.databind.DatabindException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ public NonBlockingByteArrayParser createNonBlockingByteArrayParser() throws IOEx
// 13-Mar-2021, tatu: [dataformats-binary#252] Leave async parser with
// always-canonicalizing, for now (2.13) -- to be improved in future
ByteQuadsCanonicalizer can = _byteSymbolCanonicalizer.makeChildOrPlaceholder(_factoryFeatures);
return new NonBlockingByteArrayParser(ctxt, _parserFeatures, _smileParserFeatures, can);
return new NonBlockingByteArrayParser(ctxt, _parserFeatures, _smileParserFeatures, can,
_smileBufferRecycler());
}

/*
Expand All @@ -446,7 +447,8 @@ protected SmileParser _createParser(InputStream in, IOContext ctxt) throws IOExc
{
SmileParserBootstrapper bs = new SmileParserBootstrapper(ctxt, in);
return bs.constructParser(_factoryFeatures, _parserFeatures,
_smileParserFeatures, _objectCodec, _byteSymbolCanonicalizer);
_smileParserFeatures, _objectCodec, _byteSymbolCanonicalizer,
_smileBufferRecycler());
}

@Override
Expand All @@ -473,7 +475,8 @@ protected SmileParser _createParser(byte[] data, int offset, int len, IOContext
{
return new SmileParserBootstrapper(ctxt, data, offset, len).constructParser(
_factoryFeatures, _parserFeatures, _smileParserFeatures,
_objectCodec, _byteSymbolCanonicalizer);
_objectCodec, _byteSymbolCanonicalizer,
_smileBufferRecycler());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,16 @@ private Feature(boolean defaultState) {
/**********************************************************
*/

/**
* @since 2.16
*/
public SmileParser(IOContext ctxt, int parserFeatures, int smileFeatures,
ObjectCodec codec,
ByteQuadsCanonicalizer sym,
ObjectCodec codec, ByteQuadsCanonicalizer sym,
SmileBufferRecycler sbr,
InputStream in, byte[] inputBuffer, int start, int end,
boolean bufferRecyclable)
{
super(ctxt, parserFeatures, smileFeatures, sym);
super(ctxt, parserFeatures, smileFeatures, sym, sbr);
_objectCodec = codec;

_inputStream = in;
Expand All @@ -157,6 +160,20 @@ public SmileParser(IOContext ctxt, int parserFeatures, int smileFeatures,
_bufferRecyclable = bufferRecyclable;
}

/**
* @deprecated Since 2.16
*/
@Deprecated // @since 2.16
public SmileParser(IOContext ctxt, int parserFeatures, int smileFeatures,
ObjectCodec codec, ByteQuadsCanonicalizer sym,
InputStream in, byte[] inputBuffer, int start, int end,
boolean bufferRecyclable)
{
this(ctxt, parserFeatures, smileFeatures,
codec, sym, new SmileBufferRecycler(),
in, inputBuffer, start, end, bufferRecyclable);
}

@Override
public ObjectCodec getCodec() {
return _objectCodec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fasterxml.jackson.dataformat.smile;

import java.io.IOException;
import java.lang.ref.SoftReference;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
Expand Down Expand Up @@ -239,18 +238,10 @@ public abstract class SmileParserBase extends ParserMinimalBase

/*
/**********************************************************************
/* Thread-local recycling
/* Buffer recycling
/**********************************************************************
*/

/**
* <code>ThreadLocal</code> contains a {@link java.lang.ref.SoftReference}
* to a buffer recycler used to provide a low-cost
* buffer recycling for Smile-specific buffers.
*/
protected final static ThreadLocal<SoftReference<SmileBufferRecycler>> _smileRecyclerRef
= new ThreadLocal<SoftReference<SmileBufferRecycler>>();

/**
* Helper object used for low-level recycling of Smile-generator
* specific buffers.
Expand All @@ -263,8 +254,11 @@ public abstract class SmileParserBase extends ParserMinimalBase
/**********************************************************************
*/

public SmileParserBase(IOContext ctxt, int parserFeatures, int formatFeatures,
ByteQuadsCanonicalizer sym)
/**
* @since 2.16
*/
protected SmileParserBase(IOContext ctxt, int parserFeatures, int formatFeatures,
ByteQuadsCanonicalizer sym, SmileBufferRecycler sbr)
{
super(parserFeatures);
_formatFeatures = formatFeatures;
Expand All @@ -276,26 +270,14 @@ public SmileParserBase(IOContext ctxt, int parserFeatures, int formatFeatures,
_streamReadContext = JsonReadContext.createRootContext(dups);

_textBuffer = ctxt.constructReadConstrainedTextBuffer();
_smileBufferRecycler = _smileBufferRecycler();
_smileBufferRecycler = sbr;
}

@Override
public StreamReadConstraints streamReadConstraints() {
return _ioContext.streamReadConstraints();
}

protected final static SmileBufferRecycler _smileBufferRecycler()
{
SoftReference<SmileBufferRecycler> ref = _smileRecyclerRef.get();
SmileBufferRecycler br = (ref == null) ? null : ref.get();

if (br == null) {
br = new SmileBufferRecycler();
_smileRecyclerRef.set(new SoftReference<SmileBufferRecycler>(br));
}
return br;
}

/*
/**********************************************************
/* Versioned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public SmileParserBootstrapper(IOContext ctxt, byte[] inputBuffer, int inputStar

public SmileParser constructParser(int factoryFeatures,
int generalParserFeatures, int smileFeatures,
ObjectCodec codec, ByteQuadsCanonicalizer rootByteSymbols)
ObjectCodec codec, ByteQuadsCanonicalizer rootByteSymbols,
SmileBufferRecycler sbr)
throws IOException, JsonParseException
{
// 13-Mar-2021, tatu: [dataformats-binary#252] Create canonicalizing OR
Expand All @@ -104,7 +105,7 @@ public SmileParser constructParser(int factoryFeatures,
}

SmileParser p = new SmileParser(_context, generalParserFeatures, smileFeatures,
codec, can,
codec, can, sbr,
_in, _inputBuffer, _inputPtr, _inputEnd, _bufferRecyclable);
boolean hadSig = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer;
import com.fasterxml.jackson.core.util.VersionUtil;

import com.fasterxml.jackson.dataformat.smile.SmileBufferRecycler;
import com.fasterxml.jackson.dataformat.smile.SmileConstants;
import com.fasterxml.jackson.dataformat.smile.SmileParser;
import com.fasterxml.jackson.dataformat.smile.SmileUtil;
Expand Down Expand Up @@ -52,10 +52,20 @@ public class NonBlockingByteArrayParser
/**********************************************************************
*/

public NonBlockingByteArrayParser(IOContext ctxt, int parserFeatures, int smileFeatures,
ByteQuadsCanonicalizer sym, SmileBufferRecycler sbr)
{
super(ctxt, parserFeatures, smileFeatures, sym, sbr);
}

/**
* @deprecated Since 2.16
*/
@Deprecated
public NonBlockingByteArrayParser(IOContext ctxt, int parserFeatures, int smileFeatures,
ByteQuadsCanonicalizer sym)
{
super(ctxt, parserFeatures, smileFeatures, sym);
this(ctxt, parserFeatures, smileFeatures, sym, new SmileBufferRecycler());
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,13 @@ public abstract class NonBlockingParserBase
/**********************************************************************
*/

public NonBlockingParserBase(IOContext ctxt, int parserFeatures, int smileFeatures,
ByteQuadsCanonicalizer sym)
/**
* @since 2.16
*/
protected NonBlockingParserBase(IOContext ctxt, int parserFeatures, int smileFeatures,
ByteQuadsCanonicalizer sym, SmileBufferRecycler sbr)
{
super(ctxt, parserFeatures, smileFeatures, sym);
super(ctxt, parserFeatures, smileFeatures, sym, sbr);
// We don't need a lot; for most things maximum known a-priori length below 70 bytes
_inputCopy = ctxt.allocReadIOBuffer(500);

Expand Down