Skip to content

Commit

Permalink
refactor: copy span to managed field element
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Jan 25, 2024
1 parent 767dfcf commit c5543c1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 14 deletions.
Binary file modified Assets/Dojo/.DS_Store
Binary file not shown.
27 changes: 27 additions & 0 deletions Assets/Dojo/Plugins/iOS/libdojo_c.a.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 50 additions & 1 deletion Assets/Dojo/Plugins/iOS/libdojo_c.dylib.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions Assets/Dojo/Runtime/Starknet/FieldElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,20 @@ public FieldElement(string hex)

public FieldElement(dojo.FieldElement fieldElement)
{
inner = fieldElement;
// We don't want to refer to the same memory as the original field element.
// As we might want to free it - potentially slower
// TODO: benchmark copies?
fieldElement.data.CopyTo(inner.data);
}

public FieldElement(byte[] bytes)
public FieldElement(Span<byte> bytes)
{
if (bytes.Length != 32)
{
throw new ArgumentException("Byte array must be 32 bytes.", nameof(bytes));
}

unsafe
{
fixed (byte* ptr = &inner._data[0])
{
Marshal.Copy(bytes, 0, (IntPtr)ptr, bytes.Length);
}
}
bytes.CopyTo(inner.data);
}

// This handles BigIntegers as well as primitive types
Expand Down
3 changes: 1 addition & 2 deletions Assets/Dojo/Runtime/Torii/ToriiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public List<Entity> Entities(dojo.Query query)
for (var i = 0; i < (int)result._ok.data_len; i++)
{
entities.Add(new Entity(result._ok.data[i]));
dojo.entity_free(&result._ok.data[i]);
}

dojo.carray_free(result._ok.data, result._ok.data_len);
Expand Down Expand Up @@ -180,7 +179,7 @@ private void RegisterEntityStateUpdateEvent(dojo.FieldElement[] entities, bool d
{
mappedModels[i] = new Model(models.data[i]);
// cleanup model
dojo.model_free(&models.data[i]);
// dojo.model_free(&models.data[i]);
}

// only run this when in unity play mode
Expand Down
4 changes: 2 additions & 2 deletions Assets/Spawn And Move/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
masterPrivateKey: 0x1800000000300000180000000000030000000000003006001800006600
masterAddress: 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973
masterAddress: 0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03
worldManager: {fileID: 2019443015}
worldActionsAddress: 0x3e274b7d85fd0415bec56a5d831c3854f7308bbb26d486993cfc49e5a5fb788
worldActionsAddress: 0x297bde19ca499fd8a39dd9bedbcd881a47f7b8f66c19478ce97d7de89e6112e
--- !u!4 &998234501
Transform:
m_ObjectHideFlags: 0
Expand Down

0 comments on commit c5543c1

Please sign in to comment.