From 4574489c275d64131eda819d3ad730a36e948b72 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Sat, 6 Jul 2013 10:42:34 -0700 Subject: [PATCH] make utf8 bytes response not reuse thread local buffer no need, optimized conversion to bytes anyhow, and when sending, it will just get wrapped by a buffer --- .../java/org/elasticsearch/rest/StringRestResponse.java | 9 +-------- .../java/org/elasticsearch/rest/Utf8RestResponse.java | 4 +--- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/elasticsearch/rest/StringRestResponse.java b/src/main/java/org/elasticsearch/rest/StringRestResponse.java index 55d3cb37ce7..780c7672158 100644 --- a/src/main/java/org/elasticsearch/rest/StringRestResponse.java +++ b/src/main/java/org/elasticsearch/rest/StringRestResponse.java @@ -27,13 +27,6 @@ import org.apache.lucene.util.UnicodeUtil; */ public class StringRestResponse extends Utf8RestResponse { - private static ThreadLocal cache = new ThreadLocal() { - @Override - protected BytesRef initialValue() { - return new BytesRef(); - } - }; - public StringRestResponse(RestStatus status) { super(status); } @@ -43,7 +36,7 @@ public class StringRestResponse extends Utf8RestResponse { } private static BytesRef convert(String content) { - BytesRef result = cache.get(); + BytesRef result = new BytesRef(); UnicodeUtil.UTF16toUTF8(content, 0, content.length(), result); return result; } diff --git a/src/main/java/org/elasticsearch/rest/Utf8RestResponse.java b/src/main/java/org/elasticsearch/rest/Utf8RestResponse.java index 43634277155..2953b495e1c 100644 --- a/src/main/java/org/elasticsearch/rest/Utf8RestResponse.java +++ b/src/main/java/org/elasticsearch/rest/Utf8RestResponse.java @@ -25,8 +25,6 @@ import org.apache.lucene.util.BytesRef; * An http response that is built on top of {@link org.apache.lucene.util.BytesRef}. *

*

Note, this class assumes that the utf8 result is not thread safe. - * - * */ public class Utf8RestResponse extends AbstractRestResponse implements RestResponse { @@ -58,7 +56,7 @@ public class Utf8RestResponse extends AbstractRestResponse implements RestRespon @Override public boolean contentThreadSafe() { - return false; + return true; } @Override