Created
October 21, 2014 17:54
-
-
Save ewencp/ef7343d21aa84b84526b to your computer and use it in GitHub Desktop.
snappy-cached-buffer-allocator.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/java/org/xerial/snappy/buffer/CachedBufferAllocator.java b/src/main/java/org/xerial/snappy/buffer/CachedBufferAllocator.java | |
index 2ad9926..eacc50b 100644 | |
--- a/src/main/java/org/xerial/snappy/buffer/CachedBufferAllocator.java | |
+++ b/src/main/java/org/xerial/snappy/buffer/CachedBufferAllocator.java | |
@@ -29,10 +29,16 @@ public class CachedBufferAllocator implements BufferAllocator { | |
} | |
public static synchronized CachedBufferAllocator getAllocator(int bufferSize) { | |
- if(!queueTable.containsKey(bufferSize)) { | |
- queueTable.put(bufferSize, new SoftReference<CachedBufferAllocator>(new CachedBufferAllocator(bufferSize))); | |
+ CachedBufferAllocator result = null; | |
+ | |
+ if (queueTable.containsKey(bufferSize)) { | |
+ result = queueTable.get(bufferSize).get(); | |
+ } | |
+ if (result == null) { | |
+ result = new CachedBufferAllocator(bufferSize); | |
+ queueTable.put(bufferSize, new SoftReference<CachedBufferAllocator>(result)); | |
} | |
- return queueTable.get(bufferSize).get(); | |
+ return result; | |
} | |
@Override |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment