Skip to content

Commit

Permalink
Use Encoding.UTF8 instead of allocating new (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulusParssinen authored May 13, 2024
1 parent 8856dc3 commit 951cf82
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions libs/server/Objects/Types/GarnetObjectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ public void CopyUpdate(ref IGarnetObject oldValue, ref IGarnetObject newValue, b
{
if (serializationState == (int)SerializationPhase.REST && MakeTransition(SerializationPhase.REST, SerializationPhase.SERIALIZING))
{
using (var ms = new MemoryStream())
{
using var writer = new BinaryWriter(ms, new UTF8Encoding(), true);
DoSerialize(writer);
serialized = ms.ToArray();
}
using var ms = new MemoryStream();
using var writer = new BinaryWriter(ms, Encoding.UTF8);
DoSerialize(writer);
serialized = ms.ToArray();

serializationState = (int)SerializationPhase.SERIALIZED;
return;
}
Expand Down
4 changes: 2 additions & 2 deletions libs/server/Objects/Types/GarnetObjectSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IGarnetObject Deserialize(byte[] data)
Debug.Assert(data != null);

using var ms = new MemoryStream(data);
using var binaryReader = new BinaryReader(ms, new UTF8Encoding());
using var binaryReader = new BinaryReader(ms, Encoding.UTF8);
return DeserializeInternal(binaryReader);
}

Expand Down Expand Up @@ -73,7 +73,7 @@ public static byte[] Serialize(IGarnetObject obj)
Debug.Assert(obj != null);

using var ms = new MemoryStream();
using var binaryWriter = new BinaryWriter(ms, new UTF8Encoding());
using var binaryWriter = new BinaryWriter(ms, Encoding.UTF8);
SerializeInternal(binaryWriter, obj);
return ms.ToArray();
}
Expand Down

0 comments on commit 951cf82

Please sign in to comment.