Skip to content

Commit

Permalink
make utf8 bytes response not reuse thread local buffer
Browse files Browse the repository at this point in the history
no need, optimized conversion to bytes anyhow, and when sending, it will just get wrapped by a buffer
  • Loading branch information
kimchy committed Jul 6, 2013
1 parent f4d1895 commit 4574489
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/main/java/org/elasticsearch/rest/StringRestResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
*/
public class StringRestResponse extends Utf8RestResponse {

private static ThreadLocal<BytesRef> cache = new ThreadLocal<BytesRef>() {
@Override
protected BytesRef initialValue() {
return new BytesRef();
}
};

public StringRestResponse(RestStatus status) {
super(status);
}
Expand All @@ -43,7 +36,7 @@ public StringRestResponse(RestStatus status, String content) {
}

private static BytesRef convert(String content) {
BytesRef result = cache.get();
BytesRef result = new BytesRef();
UnicodeUtil.UTF16toUTF8(content, 0, content.length(), result);
return result;
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/elasticsearch/rest/Utf8RestResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
* An http response that is built on top of {@link org.apache.lucene.util.BytesRef}.
* <p/>
* <p>Note, this class assumes that the utf8 result is not thread safe.
*
*
*/
public class Utf8RestResponse extends AbstractRestResponse implements RestResponse {

Expand Down Expand Up @@ -58,7 +56,7 @@ public Utf8RestResponse(RestStatus status, BytesRef utf8Result,

@Override
public boolean contentThreadSafe() {
return false;
return true;
}

@Override
Expand Down

0 comments on commit 4574489

Please sign in to comment.