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

Make ByteSourceJsonBootstrapper use StringReader for < 8KiB byte[] inputs #1081

Merged
merged 3 commits into from
Aug 18, 2023
Merged
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 @@ -22,6 +22,9 @@ public final class ByteSourceJsonBootstrapper
public final static byte UTF8_BOM_2 = (byte) 0xBB;
public final static byte UTF8_BOM_3 = (byte) 0xBF;

// [jackson-core#488] Limit in bytes for input byte array length to use StringReader instead of InputStreamReader
private static final int STRING_READER_BYTE_ARRAY_LENGTH_LIMIT = 8192;

/*
/**********************************************************
/* Configuration
Expand Down Expand Up @@ -230,6 +233,12 @@ public Reader constructReader() throws IOException
InputStream in = _in;

if (in == null) {
int length = _inputEnd - _inputPtr;
if (length <= STRING_READER_BYTE_ARRAY_LENGTH_LIMIT) {
// [jackson-core#488] Avoid overhead of heap ByteBuffer allocated by InputStreamReader
// when processing small inputs up to 8KiB.
return new StringReader(new String(_inputBuffer, _inputPtr, length, enc.getJavaName()));
}
in = new ByteArrayInputStream(_inputBuffer, _inputPtr, _inputEnd);
} else {
/* Also, if we have any read but unused input (usually true),
Expand Down