From 54b9d708dd31b482891f189714d2dafa57473d50 Mon Sep 17 00:00:00 2001 From: LinZhihao-723 Date: Tue, 15 Oct 2024 13:19:12 -0400 Subject: [PATCH 1/3] Fix --- .../FlattenedByteArrayFactory.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java b/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java index 79c6340..86e1bd2 100644 --- a/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java +++ b/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java @@ -4,7 +4,7 @@ import java.nio.charset.StandardCharsets; public class FlattenedByteArrayFactory { - private static ThreadLocal reusableByteArrayOutputStream; + private static ThreadLocal reusableByteArrayOutputStream = ThreadLocal.withInitial(ByteArrayOutputStream::new); /** * Constructs a FlattenedByteArray by concatenating the given byte arrays together. @@ -46,14 +46,8 @@ public static FlattenedByteArray fromStrings(String[] strings) { return EmptyArrayUtils.EMPTY_FLATTENED_BYTE_ARRAY; } - ByteArrayOutputStream outputStream; - if (null == reusableByteArrayOutputStream) { - outputStream = new ByteArrayOutputStream(); - reusableByteArrayOutputStream = ThreadLocal.withInitial(() -> outputStream); - } else { - outputStream = reusableByteArrayOutputStream.get(); - outputStream.reset(); - } + ByteArrayOutputStream outputStream = reusableByteArrayOutputStream.get(); + outputStream.reset(); int[] elemEndOffsets = new int[strings.length]; for (int i = 0; i < strings.length; ++i) { From 92c78afecf3071bf8fabbe3d16194168050db61a Mon Sep 17 00:00:00 2001 From: LinZhihao-723 Date: Tue, 15 Oct 2024 13:20:12 -0400 Subject: [PATCH 2/3] Reset signature --- .../clp/compressorfrontend/FlattenedByteArrayFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java b/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java index 86e1bd2..878b2dc 100644 --- a/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java +++ b/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java @@ -4,7 +4,7 @@ import java.nio.charset.StandardCharsets; public class FlattenedByteArrayFactory { - private static ThreadLocal reusableByteArrayOutputStream = ThreadLocal.withInitial(ByteArrayOutputStream::new); + private static final ThreadLocal reusableByteArrayOutputStream = ThreadLocal.withInitial(ByteArrayOutputStream::new); /** * Constructs a FlattenedByteArray by concatenating the given byte arrays together. From 4755ee53cc611b15beba757cba31ab8e56fb132e Mon Sep 17 00:00:00 2001 From: LinZhihao-723 Date: Tue, 15 Oct 2024 14:06:12 -0400 Subject: [PATCH 3/3] Reformat the code --- .../clp/compressorfrontend/FlattenedByteArrayFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java b/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java index 878b2dc..47b15cc 100644 --- a/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java +++ b/src/main/java/com/yscope/clp/compressorfrontend/FlattenedByteArrayFactory.java @@ -4,7 +4,8 @@ import java.nio.charset.StandardCharsets; public class FlattenedByteArrayFactory { - private static final ThreadLocal reusableByteArrayOutputStream = ThreadLocal.withInitial(ByteArrayOutputStream::new); + private static final ThreadLocal reusableByteArrayOutputStream = + ThreadLocal.withInitial(ByteArrayOutputStream::new); /** * Constructs a FlattenedByteArray by concatenating the given byte arrays together.