From 6943db5251987b0cb4848bc47aa5d256b4f53179 Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Tue, 25 Nov 2014 12:53:11 -0800 Subject: [PATCH] Changed branching logic for LZFCompressor to return null only on error, and avoid checking in most circumstances --- .../io/druid/segment/data/CompressedObjectStrategy.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java b/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java index 3ffdc737ddf..feea7d8abbf 100644 --- a/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java +++ b/processing/src/main/java/io/druid/segment/data/CompressedObjectStrategy.java @@ -211,15 +211,16 @@ public class CompressedObjectStrategy implements ObjectStrateg @Override public byte[] compress(byte[] bytes) { - LZFChunk chunk = null; + try (final ResourceHolder encoder = CompressedPools.getChunkEncoder()) { - chunk = encoder.get().encodeChunk(bytes, 0, bytes.length); + final LZFChunk chunk = encoder.get().encodeChunk(bytes, 0, bytes.length); + return chunk.getData(); } catch (IOException e) { log.error(e, "IOException thrown while closing ChunkEncoder."); } - // IOException should be on ResourceHolder.close(), not encodeChunk, so this *should* never be null - return null == chunk ? null : chunk.getData(); + // IOException should be on ResourceHolder.close(), not encodeChunk, so this *should* never happen + return null; } }