remove bytes caching for stream copy

This commit is contained in:
kimchy 2011-05-22 15:15:44 +03:00
parent 32294a4d4f
commit 9eb9e738ac
2 changed files with 1 additions and 25 deletions

View File

@ -34,7 +34,6 @@ public class CacheRecycler {
public static void clear() {
BufferRecycler.clean();
bytes.remove();
doubleObjectHashMap.remove();
longObjectHashMap.remove();
longLongHashMap.remove();
@ -47,27 +46,6 @@ public class CacheRecycler {
intArray.remove();
}
// Bytes
private static ThreadLocal<SoftReference<byte[]>> bytes = new ThreadLocal<SoftReference<byte[]>>();
public static byte[] popBytes() {
SoftReference<byte[]> ref = bytes.get();
byte[] bb = ref == null ? null : ref.get();
if (bb == null) {
bb = new byte[1024];
bytes.set(new SoftReference<byte[]>(bb));
}
return bb;
}
public static void pushBytes(byte[] bb) {
SoftReference<byte[]> ref = bytes.get();
byte[] bb1 = ref == null ? null : ref.get();
if (bb1 != null && bb1.length < bb.length) {
bytes.set(new SoftReference<byte[]>(bb));
}
}
// ----- ExtTHashMap -----
private static ThreadLocal<SoftReference<Deque<ExtTHashMap>>> hashMap = new ThreadLocal<SoftReference<Deque<ExtTHashMap>>>();

View File

@ -19,7 +19,6 @@
package org.elasticsearch.common.xcontent.json;
import org.elasticsearch.common.CacheRecycler;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.jackson.JsonGenerator;
import org.elasticsearch.common.xcontent.*;
@ -214,8 +213,7 @@ public class JsonXContentGenerator implements XContentGenerator {
generator.writeRaw(fieldName);
generator.writeRaw("\" : ");
flush();
byte[] bytes = CacheRecycler.popBytes();
Streams.copy(content, bos, bytes);
Streams.copy(content, bos);
}
@Override public void copyCurrentStructure(XContentParser parser) throws IOException {