From dbf26d19a78e05acdffcbd0206566ee84ef02235 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 1 Sep 2024 23:23:59 -0400 Subject: [PATCH 1/2] AVRO-4052: Inline BufferedBinaryEncoder writeZero method --- .../org/apache/avro/io/BufferedBinaryEncoder.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java b/lang/java/avro/src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java index 376289ec882..da04ed38a27 100644 --- a/lang/java/avro/src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java +++ b/lang/java/avro/src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java @@ -41,7 +41,7 @@ *

* To change the buffer size, configure the factory instance used to create * instances with {@link EncoderFactory#configureBufferSize(int)} - * + * * @see Encoder * @see EncoderFactory * @see BlockingBinaryEncoder @@ -105,7 +105,7 @@ private void flushBuffer() throws IOException { * current position and the end. This will not expand the buffer larger than its * current size, for writes larger than or near to the size of the buffer, we * flush the buffer and write directly to the output, bypassing the buffer. - * + * * @param num * @throws IOException */ @@ -175,14 +175,11 @@ public void writeFixed(ByteBuffer bytes) throws IOException { @Override protected void writeZero() throws IOException { - writeByte(0); - } - - private void writeByte(int b) throws IOException { + // inlined, shorter version of writeZero if (pos == buf.length) { flushBuffer(); } - buf[pos++] = (byte) (b & 0xFF); + buf[pos++] = (byte) (0); } @Override From e3e504497ed6b37751bcd55a9dca5d120329acb4 Mon Sep 17 00:00:00 2001 From: belugabehr <12578579+belugabehr@users.noreply.github.com> Date: Sat, 14 Sep 2024 14:03:24 -0400 Subject: [PATCH 2/2] Update lang/java/avro/src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java Co-authored-by: Martin Grigorov --- .../src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/java/avro/src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java b/lang/java/avro/src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java index da04ed38a27..35b515ad10a 100644 --- a/lang/java/avro/src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java +++ b/lang/java/avro/src/main/java/org/apache/avro/io/BufferedBinaryEncoder.java @@ -179,7 +179,7 @@ protected void writeZero() throws IOException { if (pos == buf.length) { flushBuffer(); } - buf[pos++] = (byte) (0); + buf[pos++] = (byte) 0; } @Override