We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7b86642 commit dfc9322Copy full SHA for dfc9322
1 file changed
src/main/java/org/xerial/snappy/buffer/CachedBufferAllocator.java
@@ -29,10 +29,16 @@ public CachedBufferAllocator(int bufferSize) {
29
}
30
31
public static synchronized CachedBufferAllocator getAllocator(int bufferSize) {
32
- if(!queueTable.containsKey(bufferSize)) {
33
- queueTable.put(bufferSize, new SoftReference<CachedBufferAllocator>(new CachedBufferAllocator(bufferSize)));
+ CachedBufferAllocator result = null;
+
34
+ if (queueTable.containsKey(bufferSize)) {
35
+ result = queueTable.get(bufferSize).get();
36
+ }
37
+ if (result == null) {
38
+ result = new CachedBufferAllocator(bufferSize);
39
+ queueTable.put(bufferSize, new SoftReference<CachedBufferAllocator>(result));
40
- return queueTable.get(bufferSize).get();
41
+ return result;
42
43
44
@Override
0 commit comments