Skip to content

Commit

Permalink
feat(android): change one byte string encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and zoomchan-cxj committed May 18, 2022
1 parent 93518b1 commit 566a2fd
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public abstract class PrimitiveValueSerializer extends SharedSerialization {
*/
private static final int SSO_SMALL_STRING_MAX_LENGTH = 32;

/**
* ISO-8859-1(Latin1) max char
*/
private static final char ISO_8859_1_MAX_CHAR = 0xff;

protected PrimitiveValueSerializer(BinaryWriter writer) {
super();

Expand Down Expand Up @@ -308,11 +313,11 @@ protected void writeString(@NonNull String value) {
// Designed to take advantage of
// https://wiki.openjdk.java.net/display/HotSpot/RangeCheckElimination
if (length > SSO_SMALL_STRING_MAX_LENGTH) {
for (char c; i < length && (c = stringWriteBuffer[i]) < 0x80; i++) {
for (char c; i < length && (c = stringWriteBuffer[i]) <= ISO_8859_1_MAX_CHAR; i++) {
writer.putByte((byte) c);
}
} else {
for (char c; i < length && (c = value.charAt(i)) < 0x80; i++) {
for (char c; i < length && (c = value.charAt(i)) <= ISO_8859_1_MAX_CHAR; i++) {
writer.putByte((byte) c);
}
}
Expand All @@ -324,7 +329,7 @@ protected void writeString(@NonNull String value) {

// region two byte string, universal path
writeTag(SerializationTag.TWO_BYTE_STRING);
writer.putVarint(length * 2);
writer.putVarint(length * 2L);
if (length > SSO_SMALL_STRING_MAX_LENGTH) {
for (i = 0; i < length; i++) {
char c = stringWriteBuffer[i];
Expand Down

0 comments on commit 566a2fd

Please sign in to comment.