Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize StringBuilder/StringBuffer serialization #908

Merged
merged 15 commits into from
Sep 27, 2023
Next Next commit
Optimize StringBuilder/StringBuffer serialization
pandalee99 committed Sep 11, 2023
commit 7db00263edcb5040725031ce259a2c0e67435be8
Original file line number Diff line number Diff line change
@@ -420,12 +420,21 @@ public StringBuilderSerializer(Fury fury) {

pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
@Override
public void write(MemoryBuffer buffer, StringBuilder value) {
stringSerializer.writeJavaString(buffer, value.toString());
int length = value.length();
buffer.writeInt(length);
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < length; i++) {
buffer.writeChar(value.charAt(i));
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
public StringBuilder read(MemoryBuffer buffer) {
return new StringBuilder(stringSerializer.readJavaString(buffer));
int length = buffer.readInt();
StringBuilder stringBuilder = new StringBuilder(length);
for (int i = 0; i < length; i++) {
stringBuilder.append(buffer.readChar());
}
return stringBuilder;
}
}

@@ -444,7 +453,11 @@ public short getXtypeId() {

pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
@Override
public void write(MemoryBuffer buffer, StringBuffer value) {
stringSerializer.writeJavaString(buffer, value.toString());
int length = value.length();
pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
buffer.writeInt(length);
for (int i = 0; i < length; i++) {
buffer.writeChar(value.charAt(i));
}
}

@Override
@@ -454,7 +467,12 @@ public void xwrite(MemoryBuffer buffer, StringBuffer value) {

pandalee99 marked this conversation as resolved.
Show resolved Hide resolved
@Override
public StringBuffer read(MemoryBuffer buffer) {
return new StringBuffer(stringSerializer.readJavaString(buffer));
int length = buffer.readInt();
StringBuffer stringBuffer = new StringBuffer(length);
for (int i = 0; i < length; i++) {
stringBuffer.append(buffer.readChar());
}
return stringBuffer;
}

@Override