Skip to content

Commit 036680e

Browse files
Instantiate row type once and reuse in bsatn deserialization
1 parent 14146e5 commit 036680e

File tree

1 file changed

+7
-4
lines changed
  • crates/bindings-csharp/BSATN.Runtime/BSATN

1 file changed

+7
-4
lines changed

crates/bindings-csharp/BSATN.Runtime/BSATN/Runtime.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ namespace SpacetimeDB.BSATN;
22

33
using System.Text;
44

5+
internal static class StructuralReadWrite<T>
6+
where T : IStructuralReadWrite, new()
7+
{
8+
public static readonly System.Func<T> Constructor = () => new T();
9+
}
10+
511
public interface IStructuralReadWrite
612
{
713
void ReadFields(BinaryReader reader);
@@ -11,10 +17,7 @@ public interface IStructuralReadWrite
1117
static T Read<T>(BinaryReader reader)
1218
where T : IStructuralReadWrite, new()
1319
{
14-
// TODO: use `RuntimeHelpers.GetUninitializedObject` as an optimisation here.
15-
// We tried but couldn't do this because BitCraft relies on being able
16-
// to add and initialize custom fields on autogenerated classes.
17-
var result = new T();
20+
var result = StructuralReadWrite<T>.Constructor();
1821
result.ReadFields(reader);
1922
return result;
2023
}

0 commit comments

Comments
 (0)