Skip to content

Commit e03d3e1

Browse files
authored
Removed a use of GetBytes in Instance.TryGetExtern and using a stack buffer instead. (#287)
1 parent 53133fa commit e03d3e1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Instance.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,11 @@ public Instance(Store store, Module module, params object[] imports)
581581

582582
private bool TryGetExtern(StoreContext context, string name, out Extern ext)
583583
{
584+
using var nameBytes = name.ToUTF8(stackalloc byte[Math.Min(64, name.Length * 2)]);
585+
584586
unsafe
585587
{
586-
var nameBytes = Encoding.UTF8.GetBytes(name);
587-
fixed (byte* ptr = nameBytes)
588+
fixed (byte* ptr = nameBytes.Span)
588589
{
589590
return Native.wasmtime_instance_export_get(context.handle, this.instance, ptr, (UIntPtr)nameBytes.Length, out ext);
590591
}

0 commit comments

Comments
 (0)