Skip to content

Instantly share code, notes, and snippets.

@ewencp
Created October 21, 2014 17:54
Show Gist options
  • Save ewencp/ef7343d21aa84b84526b to your computer and use it in GitHub Desktop.
Save ewencp/ef7343d21aa84b84526b to your computer and use it in GitHub Desktop.
snappy-cached-buffer-allocator.patch
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