Skip to content

Commit

Permalink
Reduce the number of charset lookups performed in BinaryValue under t…
Browse files Browse the repository at this point in the history
…he hood
  • Loading branch information
srgg committed Nov 16, 2016
1 parent e385fc3 commit 3e0ee3e
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
*/
public final class BinaryValue
{
/**
* It is expected that UTF-8 charset is available.
*/
private static final Charset theUTF8 = Charset.forName("UTF-8");

private final byte[] data;

private BinaryValue(byte[] data)
Expand Down Expand Up @@ -87,7 +92,7 @@ public static BinaryValue create(String data)
*/
public static BinaryValue createFromUtf8(String data)
{
return create(data, Charset.forName("UTF-8"));
return create(data, theUTF8);
}

/**
Expand Down Expand Up @@ -197,7 +202,7 @@ public String toString()
*/
public String toStringUtf8()
{
return toString(Charset.forName("UTF-8"));
return toString(theUTF8);
}

/**
Expand Down

0 comments on commit 3e0ee3e

Please sign in to comment.