From e03d3e1c57cbb50a190cfa028d192f124beac7ed Mon Sep 17 00:00:00 2001 From: Martin Evans Date: Fri, 1 Dec 2023 19:01:31 +0000 Subject: [PATCH] Removed a use of `GetBytes` in `Instance.TryGetExtern` and using a stack buffer instead. (#287) --- src/Instance.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Instance.cs b/src/Instance.cs index fdc8772..7dadd4c 100644 --- a/src/Instance.cs +++ b/src/Instance.cs @@ -581,10 +581,11 @@ public Instance(Store store, Module module, params object[] imports) private bool TryGetExtern(StoreContext context, string name, out Extern ext) { + using var nameBytes = name.ToUTF8(stackalloc byte[Math.Min(64, name.Length * 2)]); + unsafe { - var nameBytes = Encoding.UTF8.GetBytes(name); - fixed (byte* ptr = nameBytes) + fixed (byte* ptr = nameBytes.Span) { return Native.wasmtime_instance_export_get(context.handle, this.instance, ptr, (UIntPtr)nameBytes.Length, out ext); }